package com.hutao.manage.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.hutao.manage.model.AvgInHospDaysInfo;
import com.hutao.manage.model.BedIndexInfo;
import com.hutao.manage.model.CostFeeInfo;
import com.hutao.manage.model.DiagTop10DeptInfo;
import com.hutao.manage.model.DiagTop10DeptRecord;
import com.hutao.manage.model.DiagTop20OrderInfo;
import com.hutao.manage.model.GeneralPerformace;
import com.hutao.manage.model.Major20DiagInfo;
import com.hutao.manage.model.OpNumberInfo;
import com.hutao.manage.model.OperationTop20Info;
import com.hutao.manage.model.OutHospStatisIndexInfo;
import com.hutao.manage.model.OutNumDeathRateInfo;
import com.hutao.manage.model.OutPatientAgeInfo;
import com.hutao.manage.model.OutPatientAreaInfo;
import com.hutao.manage.model.OutPatientFeeInfo;
import com.hutao.manage.model.OutPatientJzyslxInfo;
import com.hutao.manage.model.OutPatientVisitInfo;
import com.hutao.manage.model.OutPatientZtqkInfo;
import com.hutao.manage.model.OutSatisContrastAnalysisInfo;
import com.hutao.manage.model.OutpatientAppointmentInfo;
import com.hutao.manage.model.OutpatientDeptInfo;
import com.hutao.manage.model.OutpatientDiagTop20Info;
import com.hutao.manage.model.OutpatientDiagTop20Record;
import com.hutao.manage.model.OutpatientSatisfactionInfo;
import com.hutao.manage.model.OutpatientSexInfo;
import com.hutao.manage.model.PerformanceInfo;
import com.hutao.manage.model.QcAcquiredInfo;
import com.hutao.manage.model.QcBackInfo;
import com.hutao.manage.model.ReportTemplate;
import com.hutao.manage.model.SingleDiagQcInfo;
import com.hutao.manage.model.TopOrderRecord;
import com.hutao.manage.pojo.DiagTop20DTO;
import com.hutao.manage.pojo.LeftMenuPojo;
import com.hutao.manage.pojo.OperationTop10PTO;
import com.hutao.manage.pojo.PageData;
import com.hutao.manage.pojo.PageParam;
import com.hutao.manage.pojo.StatisticalReportParam;
import com.hutao.manage.pojo.Top10DTO;
import com.hutao.manage.pojo.Top20DTO;
import com.hutao.manage.pojo.User;
import com.hutao.manage.service.MedicalService;
import com.hutao.manage.util.BigDecimalUtil;
import com.hutao.manage.util.DateUtil;
import com.hutao.manage.util.FileUtil;
import com.hutao.manage.util.JsonUtil;
import com.hutao.manage.util.JsonUtils;
import com.hutao.manage.util.ListSplitUtil;
import com.hutao.manage.util.MD5;
import com.hutao.manage.util.Result;
import com.hutao.manage.util.StringUtil;
import com.hutao.manage.util.WordUtil;

/**
 * 病案月报、季报、半年报、年报
 * 
 * @author 90669
 *
 */
@Controller
@RequestMapping("/report")
public class StatisticalReportsController {
	// 费用图片base64
	private static String costFeeImage;

	// 手术占比图片base64
	private static String opRateImage;

	// 手术率base64
	private static String opPrecentImage;

	// 手术节假日base64
	private static String opHolidayImage;

	// 门急诊统计指标base64
	private static String outPatientVisitImg;

	// 出院人数及死亡率base64
	private static String outDeathRateImg;
	
	//门诊总体情况base64
	private static String mzZtqkImg;
	
	//就诊医师类型img
	private static String jzyslxImg;
	
	
	//门诊预约类型img
	private static String mzyyImg;

	@Autowired
	private MedicalService medicalService;

	/**
	 * 参数设置
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping("/parameterSettingPage")
	public String parameterSettingPage(Model model) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("params_module");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		return "query/parameterSettingPage.page";
	}

	/**
	 * 参数设置
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping("/searchParameterSettingPage")
	public String searchParameterSettingPage(Model model) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("params_module");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		return "query/searchParameterSettingPage.page";
	}

	@SuppressWarnings("finally")
	@ResponseBody
	@RequestMapping("/saveParamterSetting")
	public Result saveParamterSetting(HttpServletRequest request, StatisticalReportParam statisticalReportParam) {
		Result result = null;
		try {

			String guid = StringUtil.getId();
			statisticalReportParam.setOnlyId(guid);
			statisticalReportParam.setRecordTime(new Date());

			medicalService.addParameterSetting(statisticalReportParam);

			request.getSession().setAttribute("statisticalReportParam", statisticalReportParam);

			System.out.println(statisticalReportParam);

			result = new Result(true);
		} catch (Exception e) {
			result = new Result(false);
			e.printStackTrace();
		} finally {
			return result;
		}

	}

	@ResponseBody
	@RequestMapping("/updateParamSetting")
	public Result updateParamSetting(HttpServletRequest request, Integer id) {
		Result result = null;
		try {

			StatisticalReportParam statisticalReportParam = medicalService.getParameterSettingById(id);
			statisticalReportParam.setOrganizationId("49557184-0");
			request.getSession().setAttribute("statisticalReportParam", statisticalReportParam);

			result = new Result(true);
		} catch (Exception e) {
			result = new Result(false);
			e.printStackTrace();
		} finally {
			return result;
		}

	}
	
	@ResponseBody
	@RequestMapping("/deleteParamSettingById")
	public Result deleteParamSettingById(HttpServletRequest request, Integer id) {
		Result result = null;
		try {

			medicalService.deleteParamSettingById(id);


			result = new Result(true);
		} catch (Exception e) {
			result = new Result(false);
			e.printStackTrace();
		} finally {
			return result;
		}

	}

	/**
	 * 月报
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping("/queryMedrecordHomePage")
	public String queryMedrecordHomePage(Model model) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("query_module");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		return "query/medicalHomePageQuery.page";
	}

	/**
	 * 月报首页
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@GetMapping("/edit_home_page_index_form")
	public String editHomePageIndexForm(Model model, HttpServletRequest request) {

	
		return "medical_record/home_page/edit_index_info.catalogue";
	}

	// ================================================门急诊指标start===========================================================

	// ---------------------------------------------门急诊统计指标start--------------------------------------------------
	
	
	
	@RequestMapping("/outpatientEmergencyStatisticsPage")
	public String outpatientEmergencyStatisticsPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {
			OutPatientVisitInfo outPatientVisitInfo = medicalService.getOutpatientVisit(user.getOrgCode(),
					statisticalReportParam);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				Map<String, Object> outPatientVisitInfoMap = MapUtils.getMap(jsonMap, "outPatientVisitInfo");
				if (MapUtils.isNotEmpty(outPatientVisitInfoMap)) {
					String note = MapUtils.getString(outPatientVisitInfoMap, "note");
					if (StringUtils.isNotBlank(note)) {
						outPatientVisitInfo.setNote(note);
					}
				}
			}

			model.addAttribute("outPatientVisitInfo", outPatientVisitInfo);

			model.addAttribute("outPatientVisitInfoJson", JsonUtil.objectToJson(outPatientVisitInfo));
		}

		return "query/outpatientEmergencyStatisticsPage.page";
	}

	/**
	 * 门急诊指标
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@GetMapping("/edit_home_page_basic_form")
	public String editHomePageBasicForm(Model model, HttpServletRequest request) {
		String params = request.getParameter("month");
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		try {

			OutPatientVisitInfo outPatientVisitInfo = medicalService.getOutpatientVisit(user.getOrgCode(),
					statisticalReportParam);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				Map<String, Object> outPatientVisitInfoMap = MapUtils.getMap(jsonMap, "outPatientVisitInfo");
				if (MapUtils.isNotEmpty(outPatientVisitInfoMap)) {
					String note = MapUtils.getString(outPatientVisitInfoMap, "note");
					if (StringUtils.isNotBlank(note)) {
						outPatientVisitInfo.setNote(note);
					}
				}
			}

			model.addAttribute("outPatientVisitInfo", outPatientVisitInfo);

			model.addAttribute("outPatientVisitInfoJson", JsonUtil.objectToJson(outPatientVisitInfo));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return "medical_record/home_page/edit_basic_info";
	}

	@ResponseBody
	@PostMapping("/saveOutPatientVisitInfo")
	public Result saveOutPatientVisitInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		String outPatientVisitImageBase64 = request.getParameter("outPatientVisitImageBase64");
		String note = request.getParameter("note");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {

			OutPatientVisitInfo outPatientVisitInfo = medicalService.getOutpatientVisit(user.getOrgCode(),
					statisticalReportParam);
			outPatientVisitInfo.setNote(note);
			outPatientVisitInfo.setOutPatientVisitImageBase64(StringUtils.isEmpty(outPatientVisitImageBase64) ? null
					: getBase64Image(outPatientVisitImageBase64));

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("outPatientVisitInfo", outPatientVisitInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "门急诊统计指标保存成功!");
		} catch (Exception e) {
			result = new Result(false, "门急诊统计指标保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 导出门急诊统计指标
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "exportOutPatientVisitWord")
	public void exportOutPatientVisitWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		String method = request.getParameter("method");
		String note = null;
		// 获取base64图片信息
		if ("getImage".equals(method)) {
			String image = request.getParameter("image");
			outPatientVisitImg = getBase64Image(image);
			// 导出数据
		} else {

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				Map<String, Object> outPatientVisitInfoMap = MapUtils.getMap(jsonMap, "outPatientVisitInfo");
				if (MapUtils.isNotEmpty(outPatientVisitInfoMap)) {
					note = MapUtils.getString(outPatientVisitInfoMap, "note");
				}
			}

			OutPatientVisitInfo outPatientVisitInfo = medicalService.getOutpatientVisit(user.getOrgCode(),
					statisticalReportParam);

			String summary = outPatientVisitInfo.getSummary();
			String outPatientVisitText = outPatientVisitInfo.getOutPatientVisitText();
			map.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map.put("summary", StringUtils.isEmpty(summary) ? null : summary.replaceAll("\n", "<w:br/>"));
			map.put("outPatientVisitText",
					StringUtils.isEmpty(outPatientVisitText) ? null : outPatientVisitText.replaceAll("\n", "<w:br/>"));
			map.put("outPatientVisitImg", outPatientVisitImg);
			map.put("statics1Name", statisticalReportParam.getStatics1Name());

			WordUtil.exportTemplateWord(request, response, map, "outPatientVisit.ftl", "门急诊统计指标");
		}

	}

	// ---------------------------------------------门急诊统计指标end--------------------------------------------------

	//----------------------------------------------全院门诊总体情况---------------------------------------------------------------
	
	
	@RequestMapping("/outPatientZtqk")
	public String outPatientZtqk(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		
		try {
			
		
		
		if(statisticalReportParam!=null) {
		
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
			Map<String,Object> outPatientZtqkInfoMap = null;
			if(MapUtils.isNotEmpty(jsonMap)) {
			 	outPatientZtqkInfoMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outPatientZtqkInfo");
			 	if(MapUtils.isNotEmpty(outPatientZtqkInfoMap)) {
			 		model.addAttribute("outPatientZtqkInfo", outPatientZtqkInfoMap);
			 		model.addAttribute("outPatientZtqkInfoJson", JsonUtil.objectToJson(outPatientZtqkInfoMap));
			 	}
			}
			
			if(MapUtils.isEmpty(outPatientZtqkInfoMap)) {
				OutPatientZtqkInfo outPatientZtqkInfo = medicalService.getOutPatientZtqkInfo(statisticalReportParam);
				model.addAttribute("outPatientZtqkInfo", outPatientZtqkInfo);
		 		model.addAttribute("outPatientZtqkInfoJson", JsonUtil.objectToJson(outPatientZtqkInfo));
		 		jsonMap.put("outPatientZtqkInfo", outPatientZtqkInfo);
		 		String jsonStr= JsonUtil.objectToJson(jsonMap);
		 		FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				
			}
			

			
			
		}else {
			model.addAttribute("errMsg", "请先设置参数再进行操作!");
		}

		} catch (Exception e) {
			e.printStackTrace();
		}
		

		return "query/outPatientZtqk.page";
	}

	
	@ResponseBody
	@PostMapping("/saveOutPatientZtqk")
	public Result saveOutPatientZtqk(Model model, HttpServletRequest request) {
		String ztqkImgBase64 = request.getParameter("ztqkImgBase64");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {

			OutPatientZtqkInfo outPatientZtqkInfo = medicalService.getOutPatientZtqkInfo(statisticalReportParam);
			outPatientZtqkInfo.setZtqkImgBase64(ztqkImgBase64);
			model.addAttribute("outPatientZtqkInfo", outPatientZtqkInfo);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("outPatientZtqkInfo", outPatientZtqkInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "全院门诊量总体情况保存成功!");
		} catch (Exception e) {
			result = new Result(false, "全院门诊量总体情况保存失败!");
			e.printStackTrace();
		}

		return result;
	}
	
	
	
	@ResponseBody
	@RequestMapping(value = "exportMzZtqkWord")
	public void exportMzZtqkWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		String method = request.getParameter("method");
		// 获取base64图片信息
		if ("getImage".equals(method)) {
			String image = request.getParameter("image");
			// 手术占比图片base64
			mzZtqkImg = getBase64Image(image);

	
			// 导出数据
		} else {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			
			OutPatientZtqkInfo outPatientZtqkInfo = medicalService.getOutPatientZtqkInfo(statisticalReportParam);

			map.put("note", outPatientZtqkInfo.getNote().replaceAll("\n", "<w:br/>"));
			map.put("img", mzZtqkImg);
			map.put("date", statisticalReportParam.getStatics1Name());
		
			WordUtil.exportTemplateWord(request, response, map, "mzZtqk.ftl", "门诊总体情况");
		}

	}
	
	
	
	//----------------------------------------------全院门诊总体情况---------------------------------------------------------------
	
	
	
	//----------------------------------------------全院门诊就诊医师类型---------------------------------------------------------------
	
	
	@RequestMapping("/outpatientJzyslx")
	public String outpatientJzyslx(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		
		try {
			
		
		
		if(statisticalReportParam!=null) {
		
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
			Map<String,Object> outpatientJzyslxInfoMap = null;
			if(MapUtils.isNotEmpty(jsonMap)) {
				outpatientJzyslxInfoMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientJzyslxInfo");
			 	if(MapUtils.isNotEmpty(outpatientJzyslxInfoMap)) {
			 		model.addAttribute("outpatientJzyslxInfo", outpatientJzyslxInfoMap);
			 		model.addAttribute("outpatientJzyslxInfoJson", JsonUtil.objectToJson(outpatientJzyslxInfoMap));
			 	}
			}
			
			if(MapUtils.isEmpty(outpatientJzyslxInfoMap)) {
				OutPatientJzyslxInfo outpatientJzyslxInfo = medicalService.getOutPatientJzyslxInfo(statisticalReportParam);	
				model.addAttribute("outpatientJzyslxInfo", outpatientJzyslxInfo);
				model.addAttribute("outpatientJzyslxInfoJson",JsonUtil.objectToJson(outpatientJzyslxInfo));
				jsonMap.put("outpatientJzyslxInfo", outpatientJzyslxInfo);
				String jsonStr=JsonUtil.objectToJson(jsonMap);
				FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/", statisticalReportParam.getOnlyId() + ".json");
					 
				
			}
			

			
			
		}else {
			model.addAttribute("errMsg", "请先设置参数再进行操作!");
		}

		} catch (Exception e) {
			e.printStackTrace();
		}
		

		return "query/outpatientJzyslx.page";
	}
	
	
	
	@ResponseBody
	@PostMapping("/saveOutpatientJzyslxInfo")
	public Result saveOutpatientJzyslxInfo(Model model, HttpServletRequest request) {
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {
			OutPatientJzyslxInfo outpatientJzyslxInfo = medicalService.getOutPatientJzyslxInfo(statisticalReportParam);	
			
			String jzyslxImg = request.getParameter("jzyslxImg");
			if(StringUtils.isNotBlank(jzyslxImg)) {
				outpatientJzyslxInfo.setImg(jzyslxImg);
			}
			
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("outpatientJzyslxInfo", outpatientJzyslxInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "就诊医师类型保存成功!");
		} catch (Exception e) {
			result = new Result(false, "就诊医师类型保存失败!");
			e.printStackTrace();
		}

		return result;
	}
	
	
	
	@ResponseBody
	@RequestMapping(value = "exportOutpatientJzyslx")
	public void exportOutpatientJzyslx(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		String method = request.getParameter("method");
		// 获取base64图片信息
		if ("getImage".equals(method)) {
			String image = request.getParameter("image");
			jzyslxImg = getBase64Image(image);

	
			// 导出数据
		} else {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			Map<String,Object> outpatientJzyslxInfoMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientJzyslxInfo");
			String note = null;
			if(MapUtils.isNotEmpty(outpatientJzyslxInfoMap)) {
				note = MapUtils.getString(outpatientJzyslxInfoMap, "note");
			}
			
			if(StringUtils.isEmpty(note)) {
				OutPatientJzyslxInfo outpatientJzyslxInfo = medicalService.getOutPatientJzyslxInfo(statisticalReportParam);	
				note = outpatientJzyslxInfo.getNote();
			}
			

			map.put("note", note.replaceAll("\n", "<w:br/>"));
			map.put("img", jzyslxImg);
			map.put("date", statisticalReportParam.getStatics1Name());
		
			WordUtil.exportTemplateWord(request, response, map, "zlyslx.ftl", "门诊总体情况");
		}

	}
	
	
	
	
	//----------------------------------------------全院门诊就诊医师类型---------------------------------------------------------------
	
	//----------------------------------------------1.3 门诊就诊患者性别构成---------------------------------------------------------------
	
		@RequestMapping("/outpatientSex")
		public String outpatientSex(Model model, HttpServletRequest request) {
			LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
			String leftMenuJson = JsonUtils.objectToJson(leftMenu);
			model.addAttribute("leftMenuJson", leftMenuJson);

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			
			try {
			
			if(statisticalReportParam!=null) {
			
				Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
				Map<String,Object> recordMap = null;
				if(MapUtils.isNotEmpty(jsonMap)) {
					recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientSexInfo");
				 	if(MapUtils.isNotEmpty(recordMap)) {
				 		model.addAttribute("outpatientSexInfo", recordMap);
				 		model.addAttribute("outpatientSexInfoJson", JsonUtil.objectToJson(recordMap));
				 	}
				}
				
				if(MapUtils.isEmpty(recordMap)) {
					OutpatientSexInfo outpatientSexInfo = medicalService.getOutpatientSexInfo(statisticalReportParam);	
					model.addAttribute("outpatientSexInfo", outpatientSexInfo);
					model.addAttribute("outpatientSexInfoJson",JsonUtil.objectToJson(outpatientSexInfo));
					jsonMap.put("outpatientSexInfo", outpatientSexInfo);
					String jsonStr=JsonUtil.objectToJson(jsonMap);
					FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/", statisticalReportParam.getOnlyId() + ".json");
						 
					
				}
				

				
				
			}else {
				model.addAttribute("errMsg", "请先设置参数再进行操作!");
			}

			} catch (Exception e) {
				e.printStackTrace();
			}
			

			return "query/outpatientSex.page";
		}


	
	@ResponseBody
	@PostMapping("/saveOutpatientSexInfo")
	public Result saveOutpatientSexInfo(Model model, HttpServletRequest request) {
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {
			OutpatientSexInfo outpatientSexInfo = medicalService.getOutpatientSexInfo(statisticalReportParam);
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("outpatientSexInfo", outpatientSexInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, " 门诊就诊患者性别构成保存成功!");
		} catch (Exception e) {
			result = new Result(false, "门诊就诊患者性别构成保存失败!");
			e.printStackTrace();
		}

		return result;
	}
	
	
	
	@ResponseBody
	@RequestMapping(value = "exportOutpatientSex")
	public void exportOutpatientSex(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			
			OutpatientSexInfo outpatientSexInfo = medicalService.getOutpatientSexInfo(statisticalReportParam);

			map.put("note", outpatientSexInfo.getNote().replaceAll("\n", "<w:br/>"));
		
			WordUtil.exportTemplateWord(request, response, map, "mzsex.ftl", "门诊就诊患者性别构成");
	
	}
	
	
	
	//----------------------------------------------1.3 门诊就诊患者性别构成---------------------------------------------------------------
	
	
	
	//----------------------------------------------1.4 年龄构成---------------------------------------------------------------
	
	@RequestMapping("/outpatientAge")
	public String outpatientAge(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		model.addAttribute("statisticalReportParam", statisticalReportParam);
		try {
		
		if(statisticalReportParam!=null) {
		
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
			Map<String,Object> recordMap = null;
			if(MapUtils.isNotEmpty(jsonMap)) {
				recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientAgeInfo");
			 	if(MapUtils.isNotEmpty(recordMap)) {
			 		model.addAttribute("outpatientAgeInfo", recordMap);
			 	}
			}
			
			if(MapUtils.isEmpty(recordMap)) {
				OutPatientAgeInfo outpatientAgeInfo = medicalService.getOutpatientAgeInfo(statisticalReportParam);	
				model.addAttribute("outpatientAgeInfo", outpatientAgeInfo);
				jsonMap.put("outpatientAgeInfo", outpatientAgeInfo);
				String jsonStr=JsonUtil.objectToJson(jsonMap);
				FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/", statisticalReportParam.getOnlyId() + ".json");
					 
				
			}
			

			
			
		}else {
			model.addAttribute("errMsg", "请先设置参数再进行操作!");
		}

		} catch (Exception e) {
			e.printStackTrace();
		}
		

		return "query/outpatientAge.page";
	}



@ResponseBody
@PostMapping("/saveOutpatientAgeInfo")
public Result saveOutpatientAgeInfo(Model model, HttpServletRequest request) {
	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	Result result = null;
	try {
		OutPatientAgeInfo outpatientAgeInfo = medicalService.getOutpatientAgeInfo(statisticalReportParam);	
		model.addAttribute("outpatientAgeInfo", outpatientAgeInfo);
		
		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		jsonMap.put("outpatientAgeInfo", outpatientAgeInfo);
		FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");

		result = new Result(true, " 年龄构成保存成功!");
	} catch (Exception e) {
		result = new Result(false, "年龄构成保存失败!");
		e.printStackTrace();
	}

	return result;
}



@ResponseBody
@RequestMapping(value = "exportOutpatientAge")
public void exportOutpatientAge(HttpServletRequest request, HttpServletResponse response) throws Exception {
	Map<String, Object> map = new HashMap<>();
	
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		
		OutPatientAgeInfo outpatientAgeInfo = medicalService.getOutpatientAgeInfo(statisticalReportParam);

		map.put("note", outpatientAgeInfo.getNote().replaceAll("\n", "<w:br/>"));
		map.put("list", outpatientAgeInfo.getRecordList());
		map.put("statisticalReportParam", statisticalReportParam);
	
		WordUtil.exportTemplateWord(request, response, map, "mzAge.ftl", "门诊年龄构成");

}



//----------------------------------------------1.4 年龄构成---------------------------------------------------------------




//----------------------------------------------1.5 地区构成---------------------------------------------------------------

@RequestMapping("/outpatientArea")
public String outpatientArea(Model model, HttpServletRequest request) {
	LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
	String leftMenuJson = JsonUtils.objectToJson(leftMenu);
	model.addAttribute("leftMenuJson", leftMenuJson);

	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	model.addAttribute("statisticalReportParam", statisticalReportParam);
	try {
	
	if(statisticalReportParam!=null) {
	
		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
		Map<String,Object> recordMap = null;
		if(MapUtils.isNotEmpty(jsonMap)) {
			recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientAreaInfo");
		 	if(MapUtils.isNotEmpty(recordMap)) {
		 		model.addAttribute("outpatientAreaInfo", recordMap);
		 	}
		}
		
		if(MapUtils.isEmpty(recordMap)) {
			OutPatientAreaInfo outPatientAreaInfo = medicalService.getOutpatientAreaInfo(statisticalReportParam);	
			model.addAttribute("outpatientAreaInfo", outPatientAreaInfo);
			jsonMap.put("outpatientAreaInfo", outPatientAreaInfo);
			String jsonStr=JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/", statisticalReportParam.getOnlyId() + ".json");
				 
			
		}
		

		
		
	}else {
		model.addAttribute("errMsg", "请先设置参数再进行操作!");
	}

	} catch (Exception e) {
		e.printStackTrace();
	}
	

	return "query/outpatientArea.page";
}



@ResponseBody
@PostMapping("/saveOutpatientAreaInfo")
public Result saveOutpatientAreaInfo(Model model, HttpServletRequest request) {
StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
		.getAttribute("statisticalReportParam");
Result result = null;
try {
	OutPatientAreaInfo outPatientAreaInfo = medicalService.getOutpatientAreaInfo(statisticalReportParam);
	
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	jsonMap.put("outpatientAreaInfo", outPatientAreaInfo);
	FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");

	result = new Result(true, " 地区构成保存成功!");
} catch (Exception e) {
	result = new Result(false, "地区构成保存失败!");
	e.printStackTrace();
}

return result;
}



@ResponseBody
@RequestMapping(value = "exportOutpatientArea")
public void exportOutpatientArea(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<>();

	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	
	OutPatientAreaInfo outPatientAreaInfo = medicalService.getOutpatientAreaInfo(statisticalReportParam);

	map.put("note", outPatientAreaInfo.getNote().replaceAll("\n", "<w:br/>"));
	map.put("list", outPatientAreaInfo.getList());
	map.put("statisticalReportParam", statisticalReportParam);

	WordUtil.exportTemplateWord(request, response, map, "mzArea.ftl", "门诊地区构成");

}



//----------------------------------------------1.4 地区构成---------------------------------------------------------------

	



//----------------------------------------------1.5 次均费用构成---------------------------------------------------------------

@RequestMapping("/outpatientFee")
public String outpatientFee(Model model, HttpServletRequest request) {
	LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
	String leftMenuJson = JsonUtils.objectToJson(leftMenu);
	model.addAttribute("leftMenuJson", leftMenuJson);

	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	model.addAttribute("statisticalReportParam", statisticalReportParam);
	try {
	
	if(statisticalReportParam!=null) {
	
		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
		Map<String,Object> recordMap = null;
		if(MapUtils.isNotEmpty(jsonMap)) {
			recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientFeeInfo");
		 	if(MapUtils.isNotEmpty(recordMap)) {
		 		model.addAttribute("outpatientFeeInfo", recordMap);
		 	}
		}
		
		if(MapUtils.isEmpty(recordMap)) {
			OutPatientFeeInfo outpatientFeeInfo = medicalService.getOutpatientFeeInfo(statisticalReportParam);	
			model.addAttribute("outpatientFeeInfo", outpatientFeeInfo);
			jsonMap.put("outpatientFeeInfo", outpatientFeeInfo);
			String jsonStr=JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/", statisticalReportParam.getOnlyId() + ".json");
				 
			
		}
		

		
		
	}else {
		model.addAttribute("errMsg", "请先设置参数再进行操作!");
	}

	} catch (Exception e) {
		e.printStackTrace();
	}
	

	return "query/outpatientFee.page";
}



@ResponseBody
@PostMapping("/saveOutpatientFeeInfo")
public Result saveOutpatientFeeInfo(Model model, HttpServletRequest request) {
StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
		.getAttribute("statisticalReportParam");
Result result = null;
try {
	OutPatientFeeInfo outpatientFeeInfo = medicalService.getOutpatientFeeInfo(statisticalReportParam);	
	
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	jsonMap.put("outpatientFeeInfo", outpatientFeeInfo);
	FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");

	result = new Result(true, " 次均费用保存成功!");
} catch (Exception e) {
	result = new Result(false, "次均费用保存失败!");
	e.printStackTrace();
}

return result;
}



@ResponseBody
@RequestMapping(value = "exportOutpatientFee")
public void exportOutpatientFee(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<>();

	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	
	
	String note = null;
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	Map<String,Object> recordMap = null;
	if(MapUtils.isNotEmpty(jsonMap)) {
		recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientFeeInfo");
	 	if(MapUtils.isNotEmpty(recordMap)) {
	 		note = MapUtils.getString(recordMap, "note");
	 	}
	}
	
	if(StringUtils.isEmpty(note)) {
		OutPatientFeeInfo outpatientFeeInfo = medicalService.getOutpatientFeeInfo(statisticalReportParam);	
		note=outpatientFeeInfo.getNote();	
	}
	
	map.put("note", note.replaceAll("\n", "<w:br/>"));
	map.put("statisticalReportParam", statisticalReportParam);

	WordUtil.exportTemplateWord(request, response, map, "mzFee.ftl", "次均费用构成");

}



//----------------------------------------------1.4 次均费用构成---------------------------------------------------------------

	


//----------------------------------------------1.7 门急诊患者疾病谱---------------------------------------------------------------

@RequestMapping("/outpatientDiagTop20")
public String outpatientDiagTop20(Model model, HttpServletRequest request) {
	LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
	String leftMenuJson = JsonUtils.objectToJson(leftMenu);
	model.addAttribute("leftMenuJson", leftMenuJson);

	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	model.addAttribute("statisticalReportParam", statisticalReportParam);
	try {
	
	if(statisticalReportParam!=null) {
	
		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
		Map<String,Object> recordMap = null;
		if(MapUtils.isNotEmpty(jsonMap)) {
			recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientDiagTop20Info");
		 	if(MapUtils.isNotEmpty(recordMap)) {
		 		model.addAttribute("outpatientDiagTop20Info", recordMap);
		 	}
		}
		
		if(MapUtils.isEmpty(recordMap)) {
			OutpatientDiagTop20Info outpatientDiagTop20 = medicalService.getOutpatientDiagTop20(statisticalReportParam);	
			model.addAttribute("outpatientDiagTop20Info", outpatientDiagTop20);
			jsonMap.put("outpatientDiagTop20Info", outpatientDiagTop20);
			String jsonStr=JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/", statisticalReportParam.getOnlyId() + ".json");
				 
			
		}
		

		
		
	}else {
		model.addAttribute("errMsg", "请先设置参数再进行操作!");
	}

	} catch (Exception e) {
		e.printStackTrace();
	}
	

	return "query/outpatientDiagTop20.page";
}



@ResponseBody
@PostMapping("/saveOutpatientDiagTop20Info")
public Result saveOutpatientDiagTop20Info(Model model, HttpServletRequest request) {
StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
		.getAttribute("statisticalReportParam");
Result result = null;
try {
	OutpatientDiagTop20Info outpatientDiagTop20 = medicalService.getOutpatientDiagTop20(statisticalReportParam);	
	
	
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	jsonMap.put("outpatientDiagTop20Info", outpatientDiagTop20);
	FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");

	result = new Result(true, "门急诊患者疾病谱!");
} catch (Exception e) {
	result = new Result(false, "门急诊患者疾病谱失败!");
	e.printStackTrace();
}

return result;
}



@ResponseBody
@RequestMapping(value = "exportOutpatientDiagTop20")
public void exportOutpatientDiagTop20(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<>();

	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	
	
	String note = null;
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	Map<String,Object> recordMap = null;
	List<OutpatientDiagTop20Record> list = null;
	if(MapUtils.isNotEmpty(jsonMap)) {
		recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientDiagTop20Info");
	 	if(MapUtils.isNotEmpty(recordMap)) {
	 		list = (List<OutpatientDiagTop20Record>) MapUtils.getObject(recordMap, "list");
	 	}
	}
	
	if(CollectionUtils.isEmpty(list)) {
		OutpatientDiagTop20Info outpatientDiagTop20 = medicalService.getOutpatientDiagTop20(statisticalReportParam);
		list = outpatientDiagTop20.getList();
	}
	
	//map.put("note", note.replaceAll("\n", "<w:br/>"));
	map.put("list", list);
	map.put("statisticalReportParam", statisticalReportParam);

	WordUtil.exportTemplateWord(request, response, map, "mzJbbp.ftl", "门急诊患者疾病谱");

}



//----------------------------------------------1.4 1.7 门急诊患者疾病谱---------------------------------------------------------------




//----------------------------------------------1.8 门诊提前预约情况---------------------------------------------------------------

@RequestMapping("/outpatientAppointment")
public String outpatientAppointment(Model model, HttpServletRequest request) {
	LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
	String leftMenuJson = JsonUtils.objectToJson(leftMenu);
	model.addAttribute("leftMenuJson", leftMenuJson);

	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	model.addAttribute("statisticalReportParam", statisticalReportParam);
	try {
	
	if(statisticalReportParam!=null) {
	
		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
		Map<String,Object> recordMap = null;
		if(MapUtils.isNotEmpty(jsonMap)) {
			recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientAppointmentInfo");
		 	if(MapUtils.isNotEmpty(recordMap)) {
		 		model.addAttribute("outpatientAppointmentInfo", recordMap);
		 		model.addAttribute("outpatientAppointmentInfoJson", JsonUtil.objectToJson(recordMap));
		 	}
		}
		
		if(MapUtils.isEmpty(recordMap)) {
			OutpatientAppointmentInfo OutpatientAppointmentInfo = medicalService.getOutpatientAppointment(statisticalReportParam);	
			model.addAttribute("outpatientAppointmentInfo", OutpatientAppointmentInfo);
			jsonMap.put("outpatientAppointmentInfo", OutpatientAppointmentInfo);
			model.addAttribute("outpatientAppointmentInfoJson", JsonUtil.objectToJson(OutpatientAppointmentInfo));
			String jsonStr=JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/", statisticalReportParam.getOnlyId() + ".json");
				 
			
		}
		

		
		
	}else {
		model.addAttribute("errMsg", "请先设置参数再进行操作!");
	}

	} catch (Exception e) {
		e.printStackTrace();
	}
	

	return "query/outpatientAppointment.page";
}



@ResponseBody
@PostMapping("/saveOutpatientAppointment")
public Result saveOutpatientAppointment(Model model, HttpServletRequest request) {
StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
		.getAttribute("statisticalReportParam");
Result result = null;
try {
	OutpatientAppointmentInfo OutpatientAppointmentInfo = medicalService.getOutpatientAppointment(statisticalReportParam);	
	String img = request.getParameter("img");
	if(StringUtils.isNotBlank(img)) {
		OutpatientAppointmentInfo.setImg(img);
	}
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	jsonMap.put("outpatientAppointmentInfo", OutpatientAppointmentInfo);
	FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");

	result = new Result(true, "保存门诊提前预约情况成功!");
} catch (Exception e) {
	result = new Result(false, "保存门诊提前预约情况失败!");
	e.printStackTrace();
}

return result;
}



@ResponseBody
@RequestMapping(value = "exportOutpatientAppointment")
public void exportOutpatientAppointment(HttpServletRequest request, HttpServletResponse response) throws Exception {

Map<String, Object> map = new HashMap<>();
String method = request.getParameter("method");
// 获取base64图片信息
if ("getImage".equals(method)) {
	String image = request.getParameter("image");
	mzyyImg = getBase64Image(image);


	// 导出数据
} else {
	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	Map<String,Object> recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientAppointmentInfo");
	String note = null;
	if(MapUtils.isNotEmpty(recordMap)) {
		note = MapUtils.getString(recordMap, "note");
	}
	
	if(StringUtils.isEmpty(note)) {
		OutpatientAppointmentInfo outpatientAppointmentInfo = medicalService.getOutpatientAppointment(statisticalReportParam);	
		note = outpatientAppointmentInfo.getNote();
	}
	

	map.put("note", note.replaceAll("\n", "<w:br/>"));
	map.put("img", mzyyImg);

	WordUtil.exportTemplateWord(request, response, map, "mzyy.ftl", "门诊提前预约情况");
}

}



//----------------------------------------------1.8 门诊提前预约情况---------------------------------------------------------------




//----------------------------------------------2. 各临床科室情况---------------------------------------------------------------

@RequestMapping("/outpatientDept")
public String outpatientDept(Model model, HttpServletRequest request) {
	LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("out_patient_module");
	String leftMenuJson = JsonUtils.objectToJson(leftMenu);
	model.addAttribute("leftMenuJson", leftMenuJson);

	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	model.addAttribute("statisticalReportParam", statisticalReportParam);
	try {
	
	if(statisticalReportParam!=null) {
	
		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
		Map<String,Object> recordMap = null;
		if(MapUtils.isNotEmpty(jsonMap)) {
			recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientDeptInfo");
		 	if(MapUtils.isNotEmpty(recordMap)) {
		 		model.addAttribute("outpatientDeptInfo", recordMap);
		 		model.addAttribute("outpatientDeptInfoJson", JsonUtil.objectToJson(recordMap));
		 	}
		}
		
		if(MapUtils.isEmpty(recordMap)) {
			OutpatientDeptInfo outpatientDeptInfo = medicalService.getOutpatientDeptInfo(statisticalReportParam);	
			model.addAttribute("outpatientDeptInfo", outpatientDeptInfo);
			jsonMap.put("outpatientDeptInfo", outpatientDeptInfo);
			String jsonStr=JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/", statisticalReportParam.getOnlyId() + ".json");
				 
			
		}
		

		
		
	}else {
		model.addAttribute("errMsg", "请先设置参数再进行操作!");
	}

	} catch (Exception e) {
		e.printStackTrace();
	}
	

	return "query/outpatientDept.page";
}



@ResponseBody
@PostMapping("/saveOutpatientDept")
public Result saveOutpatientDept(Model model, HttpServletRequest request) {
StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
		.getAttribute("statisticalReportParam");
Result result = null;
try {
	OutpatientAppointmentInfo OutpatientAppointmentInfo = medicalService.getOutpatientAppointment(statisticalReportParam);	
	String img = request.getParameter("img");
	if(StringUtils.isNotBlank(img)) {
		OutpatientAppointmentInfo.setImg(img);
	}
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	jsonMap.put("outpatientAppointmentInfo", OutpatientAppointmentInfo);
	FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");

	result = new Result(true, "保存门诊提前预约情况成功!");
} catch (Exception e) {
	result = new Result(false, "保存门诊提前预约情况失败!");
	e.printStackTrace();
}

return result;
}



@ResponseBody
@RequestMapping(value = "exportOutpatientDept")
public void exportOutpatientDept(HttpServletRequest request, HttpServletResponse response) throws Exception {

Map<String, Object> map = new HashMap<>();
String method = request.getParameter("method");
//获取base64图片信息
if ("getImage".equals(method)) {
	String image = request.getParameter("image");
	mzyyImg = getBase64Image(image);


	// 导出数据
} else {
	StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
			.getAttribute("statisticalReportParam");
	
	Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
			statisticalReportParam.getOnlyId() + ".json");
	Map<String,Object> recordMap = (Map<String, Object>) MapUtils.getObject(jsonMap, "outpatientAppointmentInfo");
	String note = null;
	if(MapUtils.isNotEmpty(recordMap)) {
		note = MapUtils.getString(recordMap, "note");
	}
	
	if(StringUtils.isEmpty(note)) {
		OutpatientAppointmentInfo outpatientAppointmentInfo = medicalService.getOutpatientAppointment(statisticalReportParam);	
		note = outpatientAppointmentInfo.getNote();
	}
	

	map.put("note", note.replaceAll("\n", "<w:br/>"));
	map.put("img", mzyyImg);

	WordUtil.exportTemplateWord(request, response, map, "mzyy.ftl", "门诊提前预约情况");
}

}



//----------------------------------------------2. 各临床科室情况---------------------------------------------------------------



	
	// ================================================床位相关指标start===========================================================

	@RequestMapping("/bedIndexPage")
	public String bedIndexPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("bed_index_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {
			BedIndexInfo bedIndexInfo = medicalService.getBedIndexInfo(user.getOrgCode(), statisticalReportParam);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				Map<String, Object> bedIndexInfoMap = MapUtils.getMap(jsonMap, "bedIndexInfo");
				if (MapUtils.isNotEmpty(bedIndexInfoMap)) {
					bedIndexInfo.setBedIndexNote(MapUtils.getString(bedIndexInfoMap, "bedIndexNote"));
				}
			}

			model.addAttribute("bedIndexInfo", bedIndexInfo);

		}

		return "query/bedIndexPage.page";
	}

	/**
	 * 床位相关指标
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@GetMapping("/bedRelatedIndicatorsForm")
	public String bedRelatedIndicatorsForm(Model model, HttpServletRequest request) {
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		User user = (User) request.getSession().getAttribute("user");
		BedIndexInfo bedIndexInfo = medicalService.getBedIndexInfo(user.getOrgCode(), statisticalReportParam);

		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		if (MapUtils.isNotEmpty(jsonMap)) {
			Map<String, Object> bedIndexInfoMap = MapUtils.getMap(jsonMap, "bedIndexInfo");
			if (MapUtils.isNotEmpty(bedIndexInfoMap)) {
				bedIndexInfo.setBedIndexNote(MapUtils.getString(bedIndexInfoMap, "bedIndexNote"));
			}
		}

		model.addAttribute("bedIndexInfo", bedIndexInfo);

		return "medical_record/home_page/bedRelatedIndicatorsForm";
	}

	/**
	 * 更新床位指标相关信息
	 * 
	 * @param bedRelatedIndicatorsInfo
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@PostMapping("/saveBedIndexInfo")
	public Result saveBedIndexInfo(Model model, HttpServletRequest request) {
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		Result result = null;
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			BedIndexInfo bedIndexInfo = medicalService.getBedIndexInfo(user.getOrgCode(), statisticalReportParam);

			bedIndexInfo.setBedIndexNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			jsonMap.put("bedIndexInfo", bedIndexInfo);

			String jsonStr = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonStr, "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			result = new Result(true, "床位指标保存成功!");
		} catch (IOException e) {
			result = new Result(false, "床位指标保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	@ResponseBody
	@RequestMapping(value = "exportBedIndexInfoWord")
	public void exportBedIndexInfoWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		BedIndexInfo bedIndexInfo = medicalService.getBedIndexInfo(user.getOrgCode(), statisticalReportParam);

		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		if (MapUtils.isNotEmpty(jsonMap)) {
			Map<String, Object> bedIndexInfoMap = MapUtils.getMap(jsonMap, "bedIndexInfo");
			if (MapUtils.isNotEmpty(bedIndexInfoMap)) {
				String bedIndexNote = MapUtils.getString(bedIndexInfoMap, "bedIndexNote");
				if (StringUtils.isNotEmpty(bedIndexNote)) {
					map.put("bedIndexNote", bedIndexNote.replaceAll("\n", "<w:br/>"));
				}

			}
		}

		String bedIndexText = bedIndexInfo.getBedIndexText();

		map.put("bedIndexText", StringUtils.isEmpty(bedIndexText) ? null : bedIndexText.replaceAll("\n", "<w:br/>"));

		map.put("bedIndexRecordList", bedIndexInfo.getBedIndexRecordList());

		WordUtil.exportTemplateWord(request, response, map, "bedIndex.ftl", "床位指标");

	}

	// ================================================床位相关指标end===========================================================

	// =================================================出院人数及死亡率start=========================================================

	@RequestMapping("/outNumDeathPage")
	public String outNumDeathPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("bed_index_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {
			OutNumDeathRateInfo outNumDeathRateInfo = medicalService.getOutNumAndDeathRate(statisticalReportParam,
					user.getOrgCode());

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				Map<String, Object> outNumDeathRateInfoMap = MapUtils.getMap(jsonMap, "outNumDeathRateInfo");
				if (MapUtils.isNotEmpty(outNumDeathRateInfoMap)) {
					String outNumDeathRateNote = MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateNote");
					if (StringUtils.isNotEmpty(outNumDeathRateNote)) {
						outNumDeathRateInfo.setOutNumDeathRateNote(outNumDeathRateNote);
					}

				}
			}

			model.addAttribute("outNumDeathRateInfo", outNumDeathRateInfo);

			String outNumDeathRateInfoJson = JsonUtil.objectToJson(outNumDeathRateInfo);
			model.addAttribute("outNumDeathRateInfoJson", outNumDeathRateInfoJson);

		}

		return "query/outNumDeathPage.page";
	}

	@GetMapping("/outNumsAndDeathRateForm")
	public String outNumsAndDeathRateForm(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			if (statisticalReportParam != null) {
				OutNumDeathRateInfo outNumDeathRateInfo = medicalService.getOutNumAndDeathRate(statisticalReportParam,
						user.getOrgCode());

				Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				if (MapUtils.isNotEmpty(jsonMap)) {
					Map<String, Object> outNumDeathRateInfoMap = MapUtils.getMap(jsonMap, "outNumDeathRateInfo");
					if (MapUtils.isNotEmpty(outNumDeathRateInfoMap)) {
						String outNumDeathRateNote = MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateNote");
						if (StringUtils.isNotEmpty(outNumDeathRateNote)) {
							outNumDeathRateInfo.setOutNumDeathRateNote(outNumDeathRateNote);
						}

					}
				}

				model.addAttribute("outNumDeathRateInfo", outNumDeathRateInfo);

				String outNumDeathRateInfoJson = JsonUtil.objectToJson(outNumDeathRateInfo);
				model.addAttribute("outNumDeathRateInfoJson", outNumDeathRateInfoJson);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/outNumsAndDeathRate";
	}

	@ResponseBody
	@PostMapping("/saveOutDeathRate")
	public Result saveOutDeathRate(HttpServletRequest request) {

		String image = request.getParameter("image");
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		Result result = null;
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			OutNumDeathRateInfo outNumDeathRateInfo = medicalService.getOutNumAndDeathRate(statisticalReportParam,
					user.getOrgCode());
			outNumDeathRateInfo.setOutNumDeathRateNote(note);
			outNumDeathRateInfo.setOutNumDeathRateBase64Img(getBase64Image(image));
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("outNumDeathRateInfo", outNumDeathRateInfo);

			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "出院人数及死亡率保存成功!");

		} catch (Exception e) {
			result = new Result(false, "出院人数及死亡率保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 导出出院及死亡率
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "exportOutDeathRate")
	public void exportOutDeathRate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		String method = request.getParameter("method");
		// 获取base64图片信息
		if ("getImage".equals(method)) {
			String image = request.getParameter("image");
			outDeathRateImg = getBase64Image(image);
			// 导出数据
		} else {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			String note = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				Map<String, Object> outNumDeathRateInfoMap = MapUtils.getMap(jsonMap, "outNumDeathRateInfo");
				if (MapUtils.isNotEmpty(outNumDeathRateInfoMap)) {
					note = MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateNote");
				}
			}

			OutNumDeathRateInfo outNumDeathRateInfo = medicalService.getOutNumAndDeathRate(statisticalReportParam,
					user.getOrgCode());

			String outNumDeathRateText = outNumDeathRateInfo.getOutNumDeathRateText();
			map.put("outNumDeathRateNote", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map.put("outNumDeathRateText",
					StringUtils.isEmpty(outNumDeathRateText) ? null : outNumDeathRateText.replaceAll("\n", "<w:br/>"));
			map.put("outDeathRateImg", outDeathRateImg);
			map.put("staticsName", statisticalReportParam.getStatics1Name());
			WordUtil.exportTemplateWord(request, response, map, "outDeathRate.ftl", "出院人数及死亡率");
		}

	}

	// =================================================出院人数及死亡率end=========================================================

	// ------------------------------------------------平均住院天数start------------------------------------------------------------------

	@RequestMapping("/avgInHospDaysPage")
	public String avgInHospDaysPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("bed_index_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {
			model.addAttribute("nowMonth", statisticalReportParam.getStatics1Name());
			model.addAttribute("preYearMonth", statisticalReportParam.getStatics2Name());
			model.addAttribute("preMonth", statisticalReportParam.getStatics3Name());

			AvgInHospDaysInfo avgInHospDaysInfo = null;

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				Map<String, Object> avgInHospDaysInfoMap = MapUtils.getMap(jsonMap, "avgInHospDaysInfo");
				if (MapUtils.isNotEmpty(avgInHospDaysInfoMap)) {
					// avgInHospDaysInfo.setNote(MapUtils.getString(avgInHospDaysInfoMap, "note"));
					model.addAttribute("avgInHospDaysInfo", avgInHospDaysInfoMap);
				} else {
					avgInHospDaysInfo = medicalService.getAvgInHospDays(statisticalReportParam, user.getOrgCode());
					model.addAttribute("avgInHospDaysInfo", avgInHospDaysInfo);
				}
			} else {
				avgInHospDaysInfo = medicalService.getAvgInHospDays(statisticalReportParam, user.getOrgCode());
				model.addAttribute("avgInHospDaysInfo", avgInHospDaysInfo);
			}

		}

		return "query/avgInHospDaysPage.page";
	}

	@GetMapping("/getAvgInHospDays")
	public String getAvgInHospDays(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			if (statisticalReportParam != null) {
				model.addAttribute("nowMonth", statisticalReportParam.getStatics1Name());
				model.addAttribute("preYearMonth", statisticalReportParam.getStatics2Name());
				model.addAttribute("preMonth", statisticalReportParam.getStatics3Name());

				AvgInHospDaysInfo avgInHospDaysInfo = null;

				Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				if (MapUtils.isNotEmpty(jsonMap)) {
					Map<String, Object> avgInHospDaysInfoMap = MapUtils.getMap(jsonMap, "avgInHospDaysInfo");
					if (MapUtils.isNotEmpty(avgInHospDaysInfoMap)) {
						// avgInHospDaysInfo.setNote(MapUtils.getString(avgInHospDaysInfoMap, "note"));
						model.addAttribute("avgInHospDaysInfo", avgInHospDaysInfoMap);
					} else {
						avgInHospDaysInfo = medicalService.getAvgInHospDays(statisticalReportParam, user.getOrgCode());
						model.addAttribute("avgInHospDaysInfo", avgInHospDaysInfo);
					}
				} else {
					avgInHospDaysInfo = medicalService.getAvgInHospDays(statisticalReportParam, user.getOrgCode());
					model.addAttribute("avgInHospDaysInfo", avgInHospDaysInfo);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/avgInHospDaysInfo";
	}

	@ResponseBody
	@PostMapping("/saveAvgInHospDaysInfo")
	public Result saveAvgInHospDaysInfo(HttpServletRequest request, AvgInHospDaysInfo avgInHospDaysInfo) {

		Result result = null;
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("avgInHospDaysInfo", avgInHospDaysInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "平均住院天数保存成功!");

		} catch (Exception e) {
			result = new Result(true, "平均住院天数保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	// ------------------------------------------------平均住院天数end------------------------------------------------------------------

	// =================================================疾病顺位前20统计start=========================================================

	@RequestMapping("/diagTop20Page")
	public String diagTop20Page(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("diagtop_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {

			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> diagTop20OrderInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				diagTop20OrderInfoMap = MapUtils.getMap(jsonMap, "diagTop20OrderInfo");
				if (MapUtils.isNotEmpty(diagTop20OrderInfoMap)) {
					// diagTop20OrderInfo.setTop20OrderNote(MapUtils.getString(diagTop20OrderInfoMap,
					// "top20OrderNote"));
					model.addAttribute("diagTop20OrderInfo", diagTop20OrderInfoMap);
				}
			}

			if (MapUtils.isEmpty(diagTop20OrderInfoMap)) {
				DiagTop20OrderInfo diagTop20OrderInfo = medicalService.getDiagOrderTop20(statisticalReportParam,
						user.getOrgCode(), null);

				String diagTop20Text = ReportTemplate.getDiagTop20InfoText(diagTop20OrderInfo, statisticalReportParam);
				diagTop20OrderInfo.setTop20OrderText(diagTop20Text);
				model.addAttribute("diagTop20OrderInfo", diagTop20OrderInfo);
			}

		}

		return "query/diagTop20Page.page";
	}

	@GetMapping("/diseaseOrderTop20")
	public String diseaseOrderTop20(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {

			model.addAttribute("statisticalReportParam", statisticalReportParam);
			Map<String, Object> diagTop20OrderInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				diagTop20OrderInfoMap = MapUtils.getMap(jsonMap, "diagTop20OrderInfo");
				if (MapUtils.isNotEmpty(diagTop20OrderInfoMap)) {
					// diagTop20OrderInfo.setTop20OrderNote(MapUtils.getString(diagTop20OrderInfoMap,
					// "top20OrderNote"));
					model.addAttribute("diagTop20OrderInfo", diagTop20OrderInfoMap);
				}
			}

			if (MapUtils.isEmpty(diagTop20OrderInfoMap)) {
				DiagTop20OrderInfo diagTop20OrderInfo = medicalService.getDiagOrderTop20(statisticalReportParam,
						user.getOrgCode(), null);

				String diagTop20Text = ReportTemplate.getDiagTop20InfoText(diagTop20OrderInfo, statisticalReportParam);
				diagTop20OrderInfo.setTop20OrderText(diagTop20Text);
				model.addAttribute("diagTop20OrderInfo", diagTop20OrderInfo);
			}

		}
		return "medical_record/home_page/diseaseOrderTop20";
	}

	/**
	 * 保存全院疾病顺位
	 * 
	 * @param request
	 * @param diagTop20OrderInfo
	 * @return
	 */
	@ResponseBody
	@PostMapping("/saveDiagTop20")
	public Result saveDiagTop20(HttpServletRequest request, DiagTop20OrderInfo diagTop20OrderInfo) {
		Result result = null;
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			User user = (User) request.getSession().getAttribute("user");
			DiagTop20OrderInfo dataDiagTop20OrderInfo = medicalService.getDiagOrderTop20(statisticalReportParam,
					user.getOrgCode(), null);

			if (diagTop20OrderInfo != null) {
				dataDiagTop20OrderInfo.setTop20OrderText(diagTop20OrderInfo.getTop20OrderText());
				dataDiagTop20OrderInfo.setTop20OrderNote(diagTop20OrderInfo.getTop20OrderNote());
			}

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("diagTop20OrderInfo", dataDiagTop20OrderInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			result = new Result(true, "全院疾病顺位保存成功!");
		} catch (Exception e) {
			result = new Result(false, "全院疾病顺位保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	// =================================================疾病顺位前20统计end=========================================================

	// =================================================科室疾病顺位前10统计start=========================================================

	@RequestMapping("/diagTop10Page")
	public String diagTop10Page(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("diagtop_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {

			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> diagTop10DeptInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				diagTop10DeptInfoMap = MapUtils.getMap(jsonMap, "diagTop10DeptInfo");
				if (MapUtils.isNotEmpty(diagTop10DeptInfoMap)) {
					model.addAttribute("diagTop10DeptInfo", diagTop10DeptInfoMap);
				}
			}

			if (MapUtils.isEmpty(diagTop10DeptInfoMap)) {
				DiagTop10DeptInfo diagTop10DeptInfo = medicalService.getDiagOrderTop10ByDept(statisticalReportParam,
						user.getOrgCode());

				model.addAttribute("diagTop10DeptInfo", diagTop10DeptInfo);
			}

		}

		return "query/diagTop10Page.page";
	}

	@GetMapping("/diseaseOrderTop10ByDept")
	public String diseaseOrderTop10ByDept(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			if (statisticalReportParam != null) {

				model.addAttribute("statisticalReportParam", statisticalReportParam);

				Map<String, Object> diagTop10DeptInfoMap = null;
				Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				if (MapUtils.isNotEmpty(jsonMap)) {
					diagTop10DeptInfoMap = MapUtils.getMap(jsonMap, "diagTop10DeptInfo");
					if (MapUtils.isNotEmpty(diagTop10DeptInfoMap)) {
						model.addAttribute("diagTop10DeptInfo", diagTop10DeptInfoMap);
					}
				}

				if (MapUtils.isEmpty(diagTop10DeptInfoMap)) {
					DiagTop10DeptInfo diagTop10DeptInfo = medicalService.getDiagOrderTop10ByDept(statisticalReportParam,
							user.getOrgCode());

					model.addAttribute("diagTop10DeptInfo", diagTop10DeptInfo);
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/diseaseOrderTop10ByDept";
	}

	@ResponseBody
	@PostMapping("/saveDiseaseOrderTop10ByDept")
	public Result saveDiseaseOrderTop10ByDept(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		String note = request.getParameter("note");
		Result result = null;
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			DiagTop10DeptInfo diagTop10DeptInfo = medicalService.getDiagOrderTop10ByDept(statisticalReportParam,
					user.getOrgCode());

			diagTop10DeptInfo.setNote(StringUtils.isEmpty(note) ? null : note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("diagTop10DeptInfo", diagTop10DeptInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "保存临床专科疾病顺位成功!");
		} catch (Exception e) {
			result = new Result(false, "保存临床专科疾病顺位失败!");
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 导出各临床专科疾病顺位前10位word
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "exportDiagTop10Word")
	public void exportDiagTop10Word(HttpServletRequest request, HttpServletResponse response) throws Exception {
		User user = (User) request.getSession().getAttribute("user");
		// 获取base64图片信息

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		DiagTop10DeptInfo diagTop10DeptInfo = medicalService.getDiagOrderTop10ByDept(statisticalReportParam, user.getOrgCode());

		List<DiagTop10DeptRecord> operationRecordList1 = diagTop10DeptInfo.getDiagTop10DeptRecord();

		List<DiagTop10DeptRecord> operationRecordList2 = diagTop10DeptInfo.getPreMonthDiagTop10DeptRecord();

		List<DiagTop10DeptRecord> operationRecordList3 = diagTop10DeptInfo.getLastYearDiagTop10DeptRecord();

		List<DiagTop20DTO> diagTop20DTOList = new LinkedList<DiagTop20DTO>();

		DiagTop20DTO diagTop20DTO = null;

		try {

			int index = 0;
			for (DiagTop10DeptRecord record1 : operationRecordList1) {
				diagTop20DTO = new DiagTop20DTO();

				String deptName = record1.getDeptName();
				diagTop20DTO.setDeptName(deptName);
				diagTop20DTO.setNum(4 + index);
				index++;
				List<TopOrderRecord> topOrderRecordList = record1.getDiagTop20OrderRecords();

				List<TopOrderRecord> preMonthTopOrderRecordList = null;

				List<TopOrderRecord> lastYearTopOrderRecordList = null;

				for (DiagTop10DeptRecord diagTop10DeptRecord : operationRecordList2) {
					if (deptName.equals(diagTop10DeptRecord.getDeptName())) {
						preMonthTopOrderRecordList = diagTop10DeptRecord.getDiagTop20OrderRecords();
					}
				}

				for (DiagTop10DeptRecord diagTop10DeptRecord : operationRecordList3) {
					if (deptName.equals(diagTop10DeptRecord.getDeptName())) {
						lastYearTopOrderRecordList = diagTop10DeptRecord.getDiagTop20OrderRecords();
					}
				}

				List<Top20DTO> top20DTOList = new LinkedList<Top20DTO>();
				int length = 0;
				int size = topOrderRecordList.size();
				int preMonthSize = preMonthTopOrderRecordList.size();
				int lastYearSize = lastYearTopOrderRecordList.size();
				if (size == preMonthSize && size == lastYearSize) {
					length = size;
				} else if (size >= preMonthSize && size >= lastYearSize) {
					length = size;
				} else if (preMonthSize >= size && preMonthSize >= lastYearSize) {
					length = preMonthSize;
				} else if (lastYearSize >= size && lastYearSize >= preMonthSize) {
					length = lastYearSize;
				}
				Top20DTO top20DTO = null;
				for (int i = 0; i < length; i++) {
					top20DTO = new Top20DTO();
					if (i <= (size - 1)) {

						TopOrderRecord topOrderRecord = topOrderRecordList.get(i);
						top20DTO.setTopOrder(topOrderRecord.getTopOrder());
						top20DTO.setDiagCode1(topOrderRecord.getDiagCode());
						top20DTO.setDiagName1(topOrderRecord.getDiagName());
						top20DTO.setDiagNum1(topOrderRecord.getDiagNum());
						top20DTO.setAvgInHospDays1(topOrderRecord.getAvgInHospDays());
						top20DTO.setAvgCostFee1(topOrderRecord.getAvgCostFee());

					}

					if (CollectionUtils.isNotEmpty(preMonthTopOrderRecordList)) {
						if (i <= (preMonthSize - 1)) {
							TopOrderRecord preMonthTopOrderRecord = preMonthTopOrderRecordList.get(i);
							if (top20DTO.getTopOrder() == null) {
								top20DTO.setTopOrder(preMonthTopOrderRecord.getTopOrder());
							}

							top20DTO.setDiagCode2(preMonthTopOrderRecord.getDiagCode());
							top20DTO.setDiagName2(preMonthTopOrderRecord.getDiagName());
							top20DTO.setDiagNum2(preMonthTopOrderRecord.getDiagNum());
							top20DTO.setAvgInHospDays2(preMonthTopOrderRecord.getAvgInHospDays());
							top20DTO.setAvgCostFee2(preMonthTopOrderRecord.getAvgCostFee());
						}

					}

					if (CollectionUtils.isNotEmpty(lastYearTopOrderRecordList)) {
						if (i <= (lastYearSize - 1)) {
							TopOrderRecord lastYearTopOrderRecord = lastYearTopOrderRecordList.get(i);
							if (top20DTO.getTopOrder() == null) {
								top20DTO.setTopOrder(lastYearTopOrderRecord.getTopOrder());
							}
							top20DTO.setDiagCode3(lastYearTopOrderRecord.getDiagCode());
							top20DTO.setDiagName3(lastYearTopOrderRecord.getDiagName());
							top20DTO.setDiagNum3(lastYearTopOrderRecord.getDiagNum());
							top20DTO.setAvgInHospDays3(lastYearTopOrderRecord.getAvgInHospDays());
							top20DTO.setAvgCostFee3(lastYearTopOrderRecord.getAvgCostFee());
						}

					}

					top20DTOList.add(top20DTO);

				}
				diagTop20DTO.setList(top20DTOList);
				diagTop20DTOList.add(diagTop20DTO);

				System.out.println(diagTop20DTO);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		/*
		 * List<OperationTop10PTO> operationTop10PTOList = new LinkedList<>();
		 * DiagTop10DeptRecord diagTop10DeptRecord1 = null; DiagTop10DeptRecord
		 * diagTop10DeptRecord2 = null; if (operationRecords.size() == 1) {
		 * diagTop10DeptRecord1 = operationRecords.get(0); } else if
		 * (operationRecords.size() == 2) { diagTop10DeptRecord1 =
		 * operationRecords.get(0); diagTop10DeptRecord2 = operationRecords.get(1); }
		 * String deptName1 = diagTop10DeptRecord1 == null ? null :
		 * diagTop10DeptRecord1.getDeptName(); String deptName2 = diagTop10DeptRecord2
		 * == null ? null : diagTop10DeptRecord2.getDeptName(); List<TopOrderRecord>
		 * topOrderRecordList1 = diagTop10DeptRecord1 == null ? null :
		 * diagTop10DeptRecord1.getDiagTop20OrderRecords(); List<TopOrderRecord>
		 * topOrderRecordList2 = diagTop10DeptRecord2 == null ? null :
		 * diagTop10DeptRecord2.getDiagTop20OrderRecords(); int dataSize1 =
		 * topOrderRecordList1 == null ? 0 : topOrderRecordList1.size(); int dataSize2 =
		 * topOrderRecordList2 == null ? 0 : topOrderRecordList2.size(); int size =
		 * dataSize1 >= dataSize2 ? dataSize1 : dataSize2; top10DTO.setNum(size); try {
		 * for (int i = 0; i < size; i++) { operationTop10PTO = new OperationTop10PTO();
		 * if (CollectionUtils.isNotEmpty(topOrderRecordList1)) { if (i < dataSize1) {
		 * TopOrderRecord topOrderRecord1 = topOrderRecordList1.get(i);
		 * operationTop10PTO.setDeptName(deptName1);
		 * operationTop10PTO.setDiagCode(topOrderRecord1.getDiagCode());
		 * operationTop10PTO.setDiagName(topOrderRecord1.getDiagName());
		 * operationTop10PTO.setDiagNum(topOrderRecord1.getDiagNum());
		 * operationTop10PTO.setDiagNumRate(topOrderRecord1.getDiagNumRate());
		 * operationTop10PTO.setAvgInHospDays(topOrderRecord1.getAvgInHospDays());
		 * operationTop10PTO
		 * .setAvgCostFee(BigDecimalUtil.getScale(topOrderRecord1.getAvgCostFee(), 0));
		 * } else { operationTop10PTO.setDeptName(null);
		 * operationTop10PTO.setDiagCode(null); operationTop10PTO.setDiagName(null);
		 * operationTop10PTO.setDiagNum(null); operationTop10PTO.setDiagNumRate(null);
		 * operationTop10PTO.setAvgInHospDays(null);
		 * operationTop10PTO.setAvgCostFee(null); }
		 * 
		 * }
		 * 
		 * if (CollectionUtils.isNotEmpty(topOrderRecordList2)) { if (i < dataSize2) {
		 * TopOrderRecord topOrderRecord2 = topOrderRecordList2.get(i);
		 * operationTop10PTO.setDeptName1(deptName2);
		 * operationTop10PTO.setDiagCode1(topOrderRecord2.getDiagCode());
		 * operationTop10PTO.setDiagName1(topOrderRecord2.getDiagName());
		 * operationTop10PTO.setDiagNum1(topOrderRecord2.getDiagNum());
		 * operationTop10PTO.setDiagNumRate1(topOrderRecord2.getDiagNumRate());
		 * operationTop10PTO.setAvgInHospDays1(topOrderRecord2.getAvgInHospDays());
		 * operationTop10PTO
		 * .setAvgCostFee1(BigDecimalUtil.getScale(topOrderRecord2.getAvgCostFee(), 0));
		 * } else { operationTop10PTO.setDeptName1(null);
		 * operationTop10PTO.setDiagCode1(null); operationTop10PTO.setDiagName1(null);
		 * operationTop10PTO.setDiagNum1(null); operationTop10PTO.setDiagNumRate1(null);
		 * operationTop10PTO.setAvgInHospDays1(null);
		 * operationTop10PTO.setAvgCostFee1(null); }
		 * 
		 * } operationTop10PTOList.add(operationTop10PTO);
		 * 
		 * } } catch (Exception e) { e.printStackTrace(); }
		 * 
		 * top10DTO.setList(operationTop10PTOList); top10DTOList.add(top10DTO);
		 */
		// map.put("list"+index, operationTop10PTOList);

		// index++;
		/*
		 * }
		 */

		/*
		 * Collections.sort(top10DTOList, new Comparator<Top10DTO>() {
		 * 
		 * @Override public int compare(Top10DTO o1, Top10DTO o2) {
		 * 
		 * return o2.getNum() - o1.getNum(); } }); int index = 0; for (Top10DTO top10dto
		 * : top10DTOList) { map.put("list" + index, top10dto.getList()); index++;
		 * 
		 * }
		 */
		String note = null;
		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		if (MapUtils.isNotEmpty(jsonMap)) {
			Map<String, Object> diagTop10DeptInfoMap = MapUtils.getMap(jsonMap, "diagTop10DeptInfo");
			if (MapUtils.isNotEmpty(diagTop10DeptInfoMap)) {
				note = MapUtils.getString(diagTop10DeptInfoMap, "note");

			}
		}

		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("list", diagTop20DTOList);

		dataMap.put("statisticalReportParam", statisticalReportParam);

		dataMap.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
		WordUtil.exportTemplateWord(request, response, dataMap, "diagTop10.ftl", "临床专科疾病顺位");

	}

	/**
	 * 组装疾病诊断前十顺位
	 * 
	 * @param diagTop10DeptRecordList
	 * @return
	 */
	public List<Top10DTO> getDiagTop10PTO(List<DiagTop10DeptRecord> diagTop10DeptRecordList) {
		Map<String, Object> map = new HashMap<>();
		if (CollectionUtils.isEmpty(diagTop10DeptRecordList)) {
			return null;
		}

		List<List<DiagTop10DeptRecord>> operationRecordLists = ListSplitUtil.split(diagTop10DeptRecordList, 2);
		OperationTop10PTO operationTop10PTO = null;

		List<Top10DTO> top10DTOList = new ArrayList<>();
		Top10DTO top10DTO = null;
		for (List<DiagTop10DeptRecord> operationRecords : operationRecordLists) {
			top10DTO = new Top10DTO();
			List<OperationTop10PTO> operationTop10PTOList = new LinkedList<>();
			DiagTop10DeptRecord diagTop10DeptRecord1 = null;
			DiagTop10DeptRecord diagTop10DeptRecord2 = null;
			if (operationRecords.size() == 1) {
				diagTop10DeptRecord1 = operationRecords.get(0);
			} else if (operationRecords.size() == 2) {
				diagTop10DeptRecord1 = operationRecords.get(0);
				diagTop10DeptRecord2 = operationRecords.get(1);
			}
			String deptName1 = diagTop10DeptRecord1 == null ? null : diagTop10DeptRecord1.getDeptName();
			String deptName2 = diagTop10DeptRecord2 == null ? null : diagTop10DeptRecord2.getDeptName();
			List<TopOrderRecord> topOrderRecordList1 = diagTop10DeptRecord1 == null ? null
					: diagTop10DeptRecord1.getDiagTop20OrderRecords();
			List<TopOrderRecord> topOrderRecordList2 = diagTop10DeptRecord2 == null ? null
					: diagTop10DeptRecord2.getDiagTop20OrderRecords();
			int dataSize1 = topOrderRecordList1 == null ? 0 : topOrderRecordList1.size();
			int dataSize2 = topOrderRecordList2 == null ? 0 : topOrderRecordList2.size();
			int size = dataSize1 >= dataSize2 ? dataSize1 : dataSize2;
			top10DTO.setNum(size);
			try {
				for (int i = 0; i < size; i++) {
					operationTop10PTO = new OperationTop10PTO();
					if (CollectionUtils.isNotEmpty(topOrderRecordList1)) {
						if (i < dataSize1) {
							TopOrderRecord topOrderRecord1 = topOrderRecordList1.get(i);
							operationTop10PTO.setDeptName(deptName1);
							operationTop10PTO.setDiagCode(topOrderRecord1.getDiagCode());
							operationTop10PTO.setDiagName(topOrderRecord1.getDiagName());
							operationTop10PTO.setDiagNum(topOrderRecord1.getDiagNum());
							operationTop10PTO.setDiagNumRate(topOrderRecord1.getDiagNumRate());
							operationTop10PTO.setAvgInHospDays(topOrderRecord1.getAvgInHospDays());
							operationTop10PTO
									.setAvgCostFee(BigDecimalUtil.getScale(topOrderRecord1.getAvgCostFee(), 0));
						} else {
							operationTop10PTO.setDeptName(null);
							operationTop10PTO.setDiagCode(null);
							operationTop10PTO.setDiagName(null);
							operationTop10PTO.setDiagNum(null);
							operationTop10PTO.setDiagNumRate(null);
							operationTop10PTO.setAvgInHospDays(null);
							operationTop10PTO.setAvgCostFee(null);
						}

					}

					if (CollectionUtils.isNotEmpty(topOrderRecordList2)) {
						if (i < dataSize2) {
							TopOrderRecord topOrderRecord2 = topOrderRecordList2.get(i);
							operationTop10PTO.setDeptName1(deptName2);
							operationTop10PTO.setDiagCode1(topOrderRecord2.getDiagCode());
							operationTop10PTO.setDiagName1(topOrderRecord2.getDiagName());
							operationTop10PTO.setDiagNum1(topOrderRecord2.getDiagNum());
							operationTop10PTO.setDiagNumRate1(topOrderRecord2.getDiagNumRate());
							operationTop10PTO.setAvgInHospDays1(topOrderRecord2.getAvgInHospDays());
							operationTop10PTO
									.setAvgCostFee1(BigDecimalUtil.getScale(topOrderRecord2.getAvgCostFee(), 0));
						} else {
							operationTop10PTO.setDeptName1(null);
							operationTop10PTO.setDiagCode1(null);
							operationTop10PTO.setDiagName1(null);
							operationTop10PTO.setDiagNum1(null);
							operationTop10PTO.setDiagNumRate1(null);
							operationTop10PTO.setAvgInHospDays1(null);
							operationTop10PTO.setAvgCostFee1(null);
						}

					}
					operationTop10PTOList.add(operationTop10PTO);

				}
			} catch (Exception e) {
				e.printStackTrace();
			}

			top10DTO.setList(operationTop10PTOList);
			top10DTOList.add(top10DTO);

		}

		return top10DTOList;

	}

	// =================================================科室疾病顺位前10统计end=========================================================

	// =================================================全院手术顺位start=========================================================

	@RequestMapping("/opTop20Page")
	public String opTop20Page(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("op_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {

			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			Map<String, Object> opsTop20InfoMap = null;
			if (MapUtils.isNotEmpty(jsonMap)) {
				opsTop20InfoMap = MapUtils.getMap(jsonMap, "opsTop20Info");
				if (MapUtils.isNotEmpty(opsTop20InfoMap)) {
					/*
					 * String note = MapUtils.getString(opsTop20InfoMap, "note");
					 * opsTop20Info.setNote(note);
					 */
					model.addAttribute("opsTop20Info", opsTop20InfoMap);
				}
			}

			if (MapUtils.isEmpty(opsTop20InfoMap)) {
				OperationTop20Info opsTop20Info = medicalService.getOpsTop20Order(statisticalReportParam, user.getOrgCode());
				opsTop20Info.setOperationTop20Text(
						ReportTemplate.getOpsTop20InfoText(opsTop20Info, statisticalReportParam));
				model.addAttribute("opsTop20Info", opsTop20Info);
			}

		}

		return "query/opTop20Page.page";
	}

	@GetMapping("/wholeHospitaSurgicalSequence")
	public String wholeHospitaSurgicalSequence(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			if (statisticalReportParam != null) {

				model.addAttribute("statisticalReportParam", statisticalReportParam);

				Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				Map<String, Object> opsTop20InfoMap = null;
				if (MapUtils.isNotEmpty(jsonMap)) {
					opsTop20InfoMap = MapUtils.getMap(jsonMap, "opsTop20Info");
					if (MapUtils.isNotEmpty(opsTop20InfoMap)) {
						/*
						 * String note = MapUtils.getString(opsTop20InfoMap, "note");
						 * opsTop20Info.setNote(note);
						 */
						model.addAttribute("opsTop20Info", opsTop20InfoMap);
					}
				}

				if (MapUtils.isEmpty(opsTop20InfoMap)) {
					OperationTop20Info opsTop20Info = medicalService.getOpsTop20Order(statisticalReportParam, user.getOrgCode());
					opsTop20Info.setOperationTop20Text(
							ReportTemplate.getOpsTop20InfoText(opsTop20Info, statisticalReportParam));
					model.addAttribute("opsTop20Info", opsTop20Info);
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/wholeHospitaSurgicalSequence";
	}

	@ResponseBody
	@PostMapping("/saveWholeHospitaSurgicalSequence")
	public Result saveWholeHospitaSurgicalSequence(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		String note = request.getParameter("note");
		Result result = null;
		try {

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			OperationTop20Info opsTop20Info = medicalService.getOpsTop20Order(statisticalReportParam, user.getOrgCode());
			opsTop20Info
					.setOperationTop20Text(ReportTemplate.getOpsTop20InfoText(opsTop20Info, statisticalReportParam));

			if (StringUtils.isNotBlank(note)) {
				opsTop20Info.setNote(note);
			}

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("opsTop20Info", opsTop20Info);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "手术顺位保存成功!");

		} catch (Exception e) {
			result = new Result(true, "手术顺位保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	@ResponseBody
	@RequestMapping(value = "exportOperationTop20Word")
	public void exportOperationTop20Word(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		OperationTop20Info opsTop20Info = medicalService.getOpsTop20Order(statisticalReportParam, user.getOrgCode());
		String operationTop20Text = ReportTemplate.getOpsTop20InfoText(opsTop20Info, statisticalReportParam);

		List<Top20DTO> top20DTOList = new LinkedList<>();
		List<TopOrderRecord> list1 = opsTop20Info.getTopOrderRecords();
		List<TopOrderRecord> list2 = opsTop20Info.getPreMonthTopOrderRecords();
		List<TopOrderRecord> list3 = opsTop20Info.getLastYearTopOrderRecords();
		Top20DTO top20DTO = null;
		for (int i = 0; i < list1.size(); i++) {
			TopOrderRecord record1 = list1.get(i);
			TopOrderRecord record2 = list2.get(i);
			TopOrderRecord record3 = list3.get(i);
			top20DTO = new Top20DTO();

			top20DTO.setTopOrder(record1.getTopOrder() == null ? "" : record1.getTopOrder());
			top20DTO.setDiagCode1(record1.getDiagCode() == null ? "" : record1.getDiagCode());
			top20DTO.setDiagName1(record1.getDiagName() == null ? "" : record1.getDiagName());
			top20DTO.setDiagNum1(record1.getDiagNum());
			top20DTO.setAvgInHospDays1(record1.getAvgInHospDays());
			top20DTO.setAvgCostFee1(record1.getAvgCostFee());

			top20DTO.setDiagCode2(record2.getDiagCode());
			top20DTO.setDiagName2(record2.getDiagName());
			top20DTO.setDiagNum2(record2.getDiagNum());
			top20DTO.setAvgInHospDays2(record2.getAvgInHospDays());
			top20DTO.setAvgCostFee2(record2.getAvgCostFee());

			top20DTO.setDiagCode3(record3.getDiagCode());
			top20DTO.setDiagName3(record3.getDiagName());
			top20DTO.setDiagNum3(record3.getDiagNum());
			top20DTO.setAvgInHospDays3(record3.getAvgInHospDays());
			top20DTO.setAvgCostFee3(record3.getAvgCostFee());

			if (record1.getTopOrder().equals("合计")) {
				top20DTO.setTopOrder("");
				top20DTO.setDiagCode1("合计");
			}

			System.out.println(top20DTO);

			top20DTOList.add(top20DTO);
		}

		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		if (MapUtils.isNotEmpty(jsonMap)) {
			Map<String, Object> opsTop20InfoMap = MapUtils.getMap(jsonMap, "opsTop20Info");
			if (MapUtils.isNotEmpty(opsTop20InfoMap)) {
				String note = MapUtils.getString(opsTop20InfoMap, "note");
				if (StringUtils.isNotBlank(note)) {
					map.put("note", note.replaceAll("\n", "<w:br/>"));
				}
			}
		}

		map.put("operationTop20Text", operationTop20Text.replaceAll("\n", "<w:br/>"));
		map.put("statisticalReportParam", statisticalReportParam);
		map.put("list", top20DTOList);

		WordUtil.exportTemplateWord(request, response, map, "operationTop20.ftl", "全院手术顺位");

	}

	// =================================================全院手术顺位end=========================================================

	// ===================================================临床专科科手术顺位start======================================================================

	@RequestMapping("/opTop10Page")
	public String opTop10Page(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("op_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {

			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> opsTop10InfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				opsTop10InfoMap = MapUtils.getMap(jsonMap, "opsTop10Info");
				if (MapUtils.isNotEmpty(opsTop10InfoMap)) {
					/*
					 * String note = MapUtils.getString(opsTop10InfoMap, "note"); if
					 * (StringUtils.isNotBlank(note)) { diagTop10DeptInfo.setNote(note); }
					 */
					model.addAttribute("opsTop10DeptInfo", opsTop10InfoMap);
				}
			}

			if (MapUtils.isEmpty(opsTop10InfoMap)) {
				DiagTop10DeptInfo diagTop10DeptInfo = medicalService.getOpsTop10DeptOrder(statisticalReportParam,
						user.getOrgCode());
				model.addAttribute("opsTop10DeptInfo", diagTop10DeptInfo);

			}

		}

		return "query/opTop10Page.page";
	}

	@GetMapping("/clinicalSurgicalSequence")
	public String clinicalSurgicalSequence(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			if (statisticalReportParam != null) {

				model.addAttribute("statisticalReportParam", statisticalReportParam);

				Map<String, Object> opsTop10InfoMap = null;
				Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				if (MapUtils.isNotEmpty(jsonMap)) {
					opsTop10InfoMap = MapUtils.getMap(jsonMap, "opsTop10Info");
					if (MapUtils.isNotEmpty(opsTop10InfoMap)) {
						/*
						 * String note = MapUtils.getString(opsTop10InfoMap, "note"); if
						 * (StringUtils.isNotBlank(note)) { diagTop10DeptInfo.setNote(note); }
						 */
						model.addAttribute("opsTop10DeptInfo", opsTop10InfoMap);
					}
				}

				if (MapUtils.isEmpty(opsTop10InfoMap)) {
					DiagTop10DeptInfo diagTop10DeptInfo = medicalService.getOpsTop10DeptOrder(statisticalReportParam,
							user.getOrgCode());
					model.addAttribute("opsTop10DeptInfo", diagTop10DeptInfo);

				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/clinicalSurgicalSequence";
	}

	/**
	 * 保存临床专科手术顺位
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@ResponseBody
	@PostMapping("/saveOperationTop10ByDept")
	public Result saveOperationTop10ByDept(Model model, HttpServletRequest request) {
		Result result = null;
		User user = (User) request.getSession().getAttribute("user");
		String note = request.getParameter("note");
		try {

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			DiagTop10DeptInfo diagTop10DeptInfo = medicalService.getOpsTop10DeptOrder(statisticalReportParam, user.getOrgCode());

			diagTop10DeptInfo.setNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("opsTop10Info", diagTop10DeptInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "临床专科手术顺位保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "临床专科手术顺位保存失败!");
		}

		return result;
	}

	/**
	 * 导出各临床专科手术顺位前10位word
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "exportOperationTop10Word")
	public void exportOperationTop10Word(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		DiagTop10DeptInfo diagTop10DeptInfo = medicalService.getOpsTop10DeptOrder(statisticalReportParam, user.getOrgCode());

		String note = null;
		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		if (MapUtils.isNotEmpty(jsonMap)) {
			Map<String, Object> opsTop10InfoMap = MapUtils.getMap(jsonMap, "opsTop10Info");
			if (MapUtils.isNotEmpty(opsTop10InfoMap)) {
				note = MapUtils.getString(opsTop10InfoMap, "note");

			}
		}

		List<DiagTop10DeptRecord> operationRecordList1 = diagTop10DeptInfo.getDiagTop10DeptRecord();

		List<DiagTop10DeptRecord> operationRecordList2 = diagTop10DeptInfo.getPreMonthDiagTop10DeptRecord();

		List<DiagTop10DeptRecord> operationRecordList3 = diagTop10DeptInfo.getLastYearDiagTop10DeptRecord();

		List<DiagTop20DTO> diagTop20DTOList = new LinkedList<DiagTop20DTO>();

		DiagTop20DTO diagTop20DTO = null;

		try {

			int index = 0;
			for (DiagTop10DeptRecord record1 : operationRecordList1) {
				diagTop20DTO = new DiagTop20DTO();

				String deptName = record1.getDeptName();
				diagTop20DTO.setDeptName(deptName);
				diagTop20DTO.setNum(41 + index);
				index++;
				List<TopOrderRecord> topOrderRecordList = record1.getDiagTop20OrderRecords();

				List<TopOrderRecord> preMonthTopOrderRecordList = null;

				List<TopOrderRecord> lastYearTopOrderRecordList = null;

				for (DiagTop10DeptRecord diagTop10DeptRecord : operationRecordList2) {
					if (deptName.equals(diagTop10DeptRecord.getDeptName())) {
						preMonthTopOrderRecordList = diagTop10DeptRecord.getDiagTop20OrderRecords();
					}
				}

				for (DiagTop10DeptRecord diagTop10DeptRecord : operationRecordList3) {
					if (deptName.equals(diagTop10DeptRecord.getDeptName())) {
						lastYearTopOrderRecordList = diagTop10DeptRecord.getDiagTop20OrderRecords();
					}
				}

				List<Top20DTO> top20DTOList = new LinkedList<Top20DTO>();
				int length = 0;
				int size = topOrderRecordList.size();
				int preMonthSize = preMonthTopOrderRecordList.size();
				int lastYearSize = lastYearTopOrderRecordList.size();
				if (size == preMonthSize && size == lastYearSize) {
					length = size;
				} else if (size >= preMonthSize && size >= lastYearSize) {
					length = size;
				} else if (preMonthSize >= size && preMonthSize >= lastYearSize) {
					length = preMonthSize;
				} else if (lastYearSize >= size && lastYearSize >= preMonthSize) {
					length = lastYearSize;
				}
				Top20DTO top20DTO = null;
				for (int i = 0; i < length; i++) {
					top20DTO = new Top20DTO();
					if (i <= (size - 1)) {

						TopOrderRecord topOrderRecord = topOrderRecordList.get(i);
						top20DTO.setTopOrder(topOrderRecord.getTopOrder());
						top20DTO.setDiagCode1(topOrderRecord.getDiagCode());
						top20DTO.setDiagName1(topOrderRecord.getDiagName());
						top20DTO.setDiagNum1(topOrderRecord.getDiagNum());
						top20DTO.setAvgInHospDays1(topOrderRecord.getAvgInHospDays());
						top20DTO.setAvgCostFee1(topOrderRecord.getAvgCostFee());

					}

					if (CollectionUtils.isNotEmpty(preMonthTopOrderRecordList)) {
						if (i <= (preMonthSize - 1)) {
							TopOrderRecord preMonthTopOrderRecord = preMonthTopOrderRecordList.get(i);
							if (top20DTO.getTopOrder() == null) {
								top20DTO.setTopOrder(preMonthTopOrderRecord.getTopOrder());
							}

							top20DTO.setDiagCode2(preMonthTopOrderRecord.getDiagCode());
							top20DTO.setDiagName2(preMonthTopOrderRecord.getDiagName());
							top20DTO.setDiagNum2(preMonthTopOrderRecord.getDiagNum());
							top20DTO.setAvgInHospDays2(preMonthTopOrderRecord.getAvgInHospDays());
							top20DTO.setAvgCostFee2(preMonthTopOrderRecord.getAvgCostFee());
						}

					}

					if (CollectionUtils.isNotEmpty(lastYearTopOrderRecordList)) {
						if (i <= (lastYearSize - 1)) {
							TopOrderRecord lastYearTopOrderRecord = lastYearTopOrderRecordList.get(i);
							if (top20DTO.getTopOrder() == null) {
								top20DTO.setTopOrder(lastYearTopOrderRecord.getTopOrder());
							}
							top20DTO.setDiagCode3(lastYearTopOrderRecord.getDiagCode());
							top20DTO.setDiagName3(lastYearTopOrderRecord.getDiagName());
							top20DTO.setDiagNum3(lastYearTopOrderRecord.getDiagNum());
							top20DTO.setAvgInHospDays3(lastYearTopOrderRecord.getAvgInHospDays());
							top20DTO.setAvgCostFee3(lastYearTopOrderRecord.getAvgCostFee());
						}

					}

					top20DTOList.add(top20DTO);

				}
				diagTop20DTO.setList(top20DTOList);
				diagTop20DTOList.add(diagTop20DTO);

				System.out.println(diagTop20DTO);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		/*
		 * List<DiagTop10DeptRecord> operationRecordList =
		 * diagTop10DeptInfo.getDiagTop10DeptRecord(); List<List<DiagTop10DeptRecord>>
		 * operationRecordLists = ListUtil.split(operationRecordList, 2);
		 * OperationTop10PTO operationTop10PTO = null; Map<String, Object> data = new
		 * HashMap<>(); int index = 0; for (List<DiagTop10DeptRecord> operationRecords :
		 * operationRecordLists) { List<OperationTop10PTO> operationTop10PTOList = new
		 * ArrayList<>(); DiagTop10DeptRecord diagTop10DeptRecord1 = null;
		 * DiagTop10DeptRecord diagTop10DeptRecord2 = null; if (operationRecords.size()
		 * == 1) { diagTop10DeptRecord1 = operationRecords.get(0); } else if
		 * (operationRecords.size() == 2) { diagTop10DeptRecord1 =
		 * operationRecords.get(0); diagTop10DeptRecord2 = operationRecords.get(1); }
		 * String deptName1 = diagTop10DeptRecord1 == null ? null :
		 * diagTop10DeptRecord1.getDeptName(); String deptName2 = diagTop10DeptRecord2
		 * == null ? null : diagTop10DeptRecord2.getDeptName(); List<TopOrderRecord>
		 * topOrderRecordList1 = diagTop10DeptRecord1 == null ? null :
		 * diagTop10DeptRecord1.getDiagTop20OrderRecords(); List<TopOrderRecord>
		 * topOrderRecordList2 = diagTop10DeptRecord2 == null ? null :
		 * diagTop10DeptRecord2.getDiagTop20OrderRecords(); int dataSize1 =
		 * topOrderRecordList1 == null ? 0 : topOrderRecordList1.size(); int dataSize2 =
		 * topOrderRecordList2 == null ? 0 : topOrderRecordList2.size(); int size =
		 * dataSize1 >= dataSize2 ? dataSize1 : dataSize2; for (int i = 0; i < size;
		 * i++) { operationTop10PTO = new OperationTop10PTO(); if
		 * (CollectionUtils.isNotEmpty(topOrderRecordList1)) { TopOrderRecord
		 * topOrderRecord1 = topOrderRecordList1.get(i);
		 * operationTop10PTO.setDeptName(deptName1);
		 * operationTop10PTO.setDiagCode(topOrderRecord1.getDiagCode());
		 * operationTop10PTO.setDiagName(topOrderRecord1.getDiagName());
		 * operationTop10PTO.setDiagNum(topOrderRecord1.getDiagNum());
		 * operationTop10PTO.setDiagNumRate(topOrderRecord1.getDiagNumRate());
		 * operationTop10PTO.setAvgInHospDays(topOrderRecord1.getAvgInHospDays());
		 * operationTop10PTO.setAvgCostFee(BigDecimalUtil.getScale(topOrderRecord1.
		 * getAvgCostFee(), 0)); }
		 * 
		 * if (CollectionUtils.isNotEmpty(topOrderRecordList2)) { TopOrderRecord
		 * topOrderRecord2 = topOrderRecordList2.get(i);
		 * operationTop10PTO.setDeptName1(deptName2);
		 * operationTop10PTO.setDiagCode1(topOrderRecord2.getDiagCode());
		 * operationTop10PTO.setDiagName1(topOrderRecord2.getDiagName());
		 * operationTop10PTO.setDiagNum1(topOrderRecord2.getDiagNum());
		 * operationTop10PTO.setDiagNumRate1(topOrderRecord2.getDiagNumRate());
		 * operationTop10PTO.setAvgInHospDays1(topOrderRecord2.getAvgInHospDays());
		 * operationTop10PTO.setAvgCostFee1(BigDecimalUtil.getScale(topOrderRecord2.
		 * getAvgCostFee(), 0)); } operationTop10PTOList.add(operationTop10PTO);
		 * 
		 * }
		 * 
		 * map.put("list" + index, operationTop10PTOList); index++;
		 * 
		 * } Map<String, Object> dataMap = new HashMap<>(); dataMap.put("map", map);
		 */
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("list", diagTop20DTOList);
		dataMap.put("statisticalReportParam", statisticalReportParam);
		dataMap.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
		WordUtil.exportTemplateWord(request, response, dataMap, "operationTop10.ftl", "临床专科手术顺位");

	}

	// ===================================================临床转科手术顺位end======================================================================

	// ===================================================死亡原因顺位start======================================================================

	@RequestMapping("/deathReasonPage")
	public String deathReasonPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("death_reason_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		if (statisticalReportParam != null) {

			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> deathReasonInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				deathReasonInfoMap = MapUtils.getMap(jsonMap, "deathReasonInfo");
				if (MapUtils.isNotEmpty(deathReasonInfoMap)) {
					String top20OrderNote = MapUtils.getString(deathReasonInfoMap, "top20OrderNote");
					if (StringUtils.isNotBlank(top20OrderNote)) {
						model.addAttribute("deathReasonInfo", deathReasonInfoMap);
					}
				}
			}

			if (MapUtils.isEmpty(deathReasonInfoMap)) {
				DiagTop20OrderInfo deathReasonInfo = medicalService.getDeathSequence(statisticalReportParam, user.getOrgCode(),
						"5");
				String diagTop20Text = ReportTemplate.getDeathReasonInfoText(deathReasonInfo, statisticalReportParam);
				deathReasonInfo.setTop20OrderText(diagTop20Text);

				model.addAttribute("deathReasonInfo", deathReasonInfo);
			}

		}

		return "query/deathReasonPage.page";
	}

	@GetMapping("/deathReasonSequence")
	public String deathReasonSequence(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			if (statisticalReportParam != null) {

				model.addAttribute("statisticalReportParam", statisticalReportParam);

				Map<String, Object> deathReasonInfoMap = null;
				Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				if (MapUtils.isNotEmpty(jsonMap)) {
					deathReasonInfoMap = MapUtils.getMap(jsonMap, "deathReasonInfo");
					if (MapUtils.isNotEmpty(deathReasonInfoMap)) {
						String top20OrderNote = MapUtils.getString(deathReasonInfoMap, "top20OrderNote");
						if (StringUtils.isNotBlank(top20OrderNote)) {
							model.addAttribute("deathReasonInfo", deathReasonInfoMap);
						}
					}
				}

				if (MapUtils.isEmpty(deathReasonInfoMap)) {
					DiagTop20OrderInfo deathReasonInfo = medicalService.getDeathSequence(statisticalReportParam,
							user.getOrgCode(), "5");
					String diagTop20Text = ReportTemplate.getDeathReasonInfoText(deathReasonInfo,
							statisticalReportParam);
					deathReasonInfo.setTop20OrderText(diagTop20Text);

					model.addAttribute("deathReasonInfo", deathReasonInfo);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/deathReasonSequence";
	}

	@ResponseBody
	@PostMapping("/saveDeathTop20Info")
	public Result saveDeathTop20Info(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		String note = request.getParameter("note");
		Result result = null;
		try {

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			DiagTop20OrderInfo deathReasonInfo = medicalService.getDeathSequence(statisticalReportParam, user.getOrgCode(), "5");

			String diagTop20Text = ReportTemplate.getDeathReasonInfoText(deathReasonInfo, statisticalReportParam);
			deathReasonInfo.setTop20OrderText(diagTop20Text);
			deathReasonInfo.setTop20OrderNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("deathReasonInfo", deathReasonInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "死因顺位保存成功!");
		} catch (Exception e) {
			result = new Result(true, "死因顺位保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	@ResponseBody
	@RequestMapping(value = "exportDeathTop20Word")
	public void exportDeathTop20Word(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		DiagTop20OrderInfo deathReasonInfo = medicalService.getDeathSequence(statisticalReportParam, user.getOrgCode(), "5");

		String diagTop20Text = ReportTemplate.getDeathReasonInfoText(deathReasonInfo, statisticalReportParam);
		deathReasonInfo.setTop20OrderText(diagTop20Text);

		List<Top20DTO> top20DTOList = new LinkedList<>();
		List<TopOrderRecord> list1 = deathReasonInfo.getTop20diagOrderRecords();
		List<TopOrderRecord> list2 = deathReasonInfo.getPreMonthtop20diagOrderRecords();
		List<TopOrderRecord> list3 = deathReasonInfo.getLastYeartop20diagOrderRecords();
		Top20DTO top20DTO = null;
		for (int i = 0; i < list1.size(); i++) {
			TopOrderRecord record1 = list1.get(i);
			TopOrderRecord record2 = list2.get(i);
			TopOrderRecord record3 = list3.get(i);
			top20DTO = new Top20DTO();

			top20DTO.setTopOrder(record1.getTopOrder() == null ? "" : record1.getTopOrder());
			top20DTO.setDiagCode1(record1.getDiagCode() == null ? "" : record1.getDiagCode());
			top20DTO.setDiagName1(record1.getDiagName() == null ? "" : record1.getDiagName());
			top20DTO.setDiagNum1(record1.getDiagNum());
			top20DTO.setAvgInHospDays1(record1.getAvgInHospDays());
			top20DTO.setAvgCostFee1(record1.getAvgCostFee());

			top20DTO.setDiagCode2(record2.getDiagCode());
			top20DTO.setDiagName2(record2.getDiagName());
			top20DTO.setDiagNum2(record2.getDiagNum());
			top20DTO.setAvgInHospDays2(record2.getAvgInHospDays());
			top20DTO.setAvgCostFee2(record2.getAvgCostFee());

			top20DTO.setDiagCode3(record3.getDiagCode());
			top20DTO.setDiagName3(record3.getDiagName());
			top20DTO.setDiagNum3(record3.getDiagNum());
			top20DTO.setAvgInHospDays3(record3.getAvgInHospDays());
			top20DTO.setAvgCostFee3(record3.getAvgCostFee());

			if (record1.getTopOrder().equals("合计")) {
				top20DTO.setTopOrder("");
				top20DTO.setDiagCode1("合计");
			}

			System.out.println(top20DTO);

			top20DTOList.add(top20DTO);
		}

		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		if (MapUtils.isNotEmpty(jsonMap)) {
			Map<String, Object> deathReasonInfoMap = MapUtils.getMap(jsonMap, "deathReasonInfo");
			if (MapUtils.isNotEmpty(deathReasonInfoMap)) {
				String note = MapUtils.getString(deathReasonInfoMap, "top20OrderNote");
				map.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			}
		}

		map.put("top20OrderText", diagTop20Text.replaceAll("\n", "<w:br/>"));
		map.put("statisticalReportParam", statisticalReportParam);
		map.put("list", top20DTOList);

		WordUtil.exportTemplateWord(request, response, map, "deathTop20.ftl", "死因顺位指标");

	}

	// ===================================================临床转科手术顺位end======================================================================

	// ===================================================费用start======================================================================

	@RequestMapping("/costFeeInfoPage")
	public String costFeeInfoPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("bed_index_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		try {

			Map<String, Object> costFeeInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				costFeeInfoMap = MapUtils.getMap(jsonMap, "costFeeInfo");
				if (MapUtils.isNotEmpty(costFeeInfoMap)) {
					model.addAttribute("costFeeInfo", costFeeInfoMap);
					model.addAttribute("costFeeInfoJson", JsonUtil.objectToJson(costFeeInfoMap));
				}
			}
			if (MapUtils.isEmpty(costFeeInfoMap)) {
				CostFeeInfo costFeeInfo = medicalService.getCostFeeInfo(statisticalReportParam, user.getOrgCode());
				String costText = ReportTemplate.getCostInfoText(costFeeInfo, statisticalReportParam);
				costFeeInfo.setCostText(costText);
				model.addAttribute("costFeeInfo", costFeeInfo);
				model.addAttribute("costFeeInfoJson", JsonUtil.objectToJson(costFeeInfo));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/costFeeInfoPage.page";
	}

	@SuppressWarnings("unchecked")
	@GetMapping("/costFeeInfo")
	public String costFeeInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		try {

			Map<String, Object> costFeeInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				costFeeInfoMap = MapUtils.getMap(jsonMap, "costFeeInfo");
				if (MapUtils.isNotEmpty(costFeeInfoMap)) {
					model.addAttribute("costFeeInfo", costFeeInfoMap);
					model.addAttribute("costFeeInfoJson", JsonUtil.objectToJson(costFeeInfoMap));
				}
			}
			if (MapUtils.isEmpty(costFeeInfoMap)) {
				CostFeeInfo costFeeInfo = medicalService.getCostFeeInfo(statisticalReportParam, user.getOrgCode());
				String costText = ReportTemplate.getCostInfoText(costFeeInfo, statisticalReportParam);
				costFeeInfo.setCostText(costText);
				model.addAttribute("costFeeInfo", costFeeInfo);
				model.addAttribute("costFeeInfoJson", JsonUtil.objectToJson(costFeeInfo));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/costFeeInfo";
	}

	@ResponseBody
	@PostMapping("/saveCostFeeInfo")
	public Result saveCostFeeInfo(CostFeeInfo costFeeInfo, HttpServletRequest request) {
		Result result = null;
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			CostFeeInfo dataCostFeeInfo = medicalService.getCostFeeInfo(statisticalReportParam, user.getOrgCode());
			if (costFeeInfo != null) {

				String costText = ReportTemplate.getCostInfoText(dataCostFeeInfo, statisticalReportParam);
				dataCostFeeInfo.setCostText(costText);

				dataCostFeeInfo.setCostFeeNote(costFeeInfo.getCostFeeNote());
				if (costFeeInfo.getCostFeeBase64Image() != null) {
					dataCostFeeInfo.setCostFeeBase64Image(getBase64Image(costFeeInfo.getCostFeeBase64Image()));
				}

			}

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("costFeeInfo", dataCostFeeInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			result = new Result(true, "费用信息保存成功!");
		} catch (Exception e) {
			result = new Result(false, "费用信息保存失败!");
			e.printStackTrace();
		}
		return result;
	}

	// ===================================================费用end======================================================================

	// ===================================================手术及操作人次数start======================================================================

	@RequestMapping("/opNumberInfoPage")
	public String opNumberInfoPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("bed_index_module");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		User user = (User) request.getSession().getAttribute("user");
		try {

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			Map<String, Object> opNumberInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (jsonMap != null) {
				opNumberInfoMap = MapUtils.getMap(jsonMap, "opNumberInfo");
				if (MapUtils.isNotEmpty(opNumberInfoMap)) {
					/*
					 * opNumberInfo.setOpRateNote(MapUtils.getString(opNumberInfoMap,
					 * "opRateNote"));
					 * opNumberInfo.setThirdForthOpRatioNote(MapUtils.getString(opNumberInfoMap,
					 * "thirdForthOpRatioNote"));
					 */
					model.addAttribute("opNumberInfo", opNumberInfoMap);
					model.addAttribute("opNumberInfoJson", JsonUtil.objectToJson(opNumberInfoMap));
				}
			}

			if (MapUtils.isEmpty(opNumberInfoMap)) {
				OpNumberInfo opNumberInfo = medicalService.getOpNumberInfo(statisticalReportParam, user.getOrgCode());

				String opRatioText = ReportTemplate.getOpRatioText(opNumberInfo, statisticalReportParam);
				opNumberInfo.setOpRatioText(opRatioText);
				String thirdForthOpRatioText = ReportTemplate.getThirdForthOpRatioText(opNumberInfo,
						statisticalReportParam);
				opNumberInfo.setThirdForthOpRatioText(thirdForthOpRatioText);
				model.addAttribute("opNumberInfo", opNumberInfo);
				model.addAttribute("opNumberInfoJson", JsonUtil.objectToJson(opNumberInfo));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return "query/opNumberInfoPage.page";
	}

	@GetMapping("/opNumberInfo")
	public String opNumberInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			Map<String, Object> opNumberInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (jsonMap != null) {
				opNumberInfoMap = MapUtils.getMap(jsonMap, "opNumberInfo");
				if (MapUtils.isNotEmpty(opNumberInfoMap)) {
					/*
					 * opNumberInfo.setOpRateNote(MapUtils.getString(opNumberInfoMap,
					 * "opRateNote"));
					 * opNumberInfo.setThirdForthOpRatioNote(MapUtils.getString(opNumberInfoMap,
					 * "thirdForthOpRatioNote"));
					 */
					model.addAttribute("opNumberInfo", opNumberInfoMap);
					model.addAttribute("opNumberInfoJson", JsonUtil.objectToJson(opNumberInfoMap));
				}
			}

			if (MapUtils.isEmpty(opNumberInfoMap)) {
				OpNumberInfo opNumberInfo = medicalService.getOpNumberInfo(statisticalReportParam, user.getOrgCode());

				String opRatioText = ReportTemplate.getOpRatioText(opNumberInfo, statisticalReportParam);
				opNumberInfo.setOpRatioText(opRatioText);
				String thirdForthOpRatioText = ReportTemplate.getThirdForthOpRatioText(opNumberInfo,
						statisticalReportParam);
				opNumberInfo.setThirdForthOpRatioText(thirdForthOpRatioText);
				model.addAttribute("opNumberInfo", opNumberInfo);
				model.addAttribute("opNumberInfoJson", JsonUtil.objectToJson(opNumberInfo));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return "medical_record/home_page/opNumberInfo";
	}

	/**
	 * 保存手术及操作人次数顺位
	 * 
	 * @param request
	 * @param diagTop20OrderInfo
	 * @return
	 */
	@ResponseBody
	@PostMapping("/saveOpNumberInfo")
	public Result saveOpNumberInfo(HttpServletRequest request, OpNumberInfo opNumberInfo) {
		Result result = null;
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			User user = (User) request.getSession().getAttribute("user");
			OpNumberInfo dataOpNumberInfo = medicalService.getOpNumberInfo(statisticalReportParam, user.getOrgCode());

			String opRatioText = ReportTemplate.getOpRatioText(dataOpNumberInfo, statisticalReportParam);

			dataOpNumberInfo.setOpRatioText(opRatioText);

			String thirdForthOpRatioText = ReportTemplate.getThirdForthOpRatioText(dataOpNumberInfo,
					statisticalReportParam);
			dataOpNumberInfo.setThirdForthOpRatioText(thirdForthOpRatioText);

			if (opNumberInfo != null) {
				dataOpNumberInfo.setOpRateNote(opNumberInfo.getOpRateNote());
				dataOpNumberInfo.setThirdForthOpRatioNote(opNumberInfo.getThirdForthOpRatioNote());
				dataOpNumberInfo.setEchart1Image(opNumberInfo.getEchart1Image());
				dataOpNumberInfo.setEchart2Image(opNumberInfo.getEchart2Image());
				dataOpNumberInfo.setEchart3Image(opNumberInfo.getEchart3Image());
			}

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("opNumberInfo", dataOpNumberInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			result = new Result(true, "手术及操作人次数保存成功!");
		} catch (Exception e) {
			result = new Result(false, "手术及操作人次数保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	@ResponseBody
	@RequestMapping(value = "exportOpNumInfoWord")
	public void exportOpNumInfoWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		String params = request.getParameter("month");
		String method = request.getParameter("method");
		String guid = MD5.md5(params);
		// 获取base64图片信息
		if ("getImage".equals(method)) {
			String image = request.getParameter("image");
			// 手术占比图片base64
			opRateImage = getBase64Image(image);

			String image1 = request.getParameter("image1");
			// 手术率base64
			opPrecentImage = getBase64Image(image1);

			// 手术节假日base64
			String image2 = request.getParameter("image2");
			// 手术率base64
			opHolidayImage = getBase64Image(image2);

			// 导出数据
		} else {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			OpNumberInfo opNumberInfo = medicalService.getOpNumberInfo(statisticalReportParam, user.getOrgCode());

			String opRatioText = ReportTemplate.getOpRatioText(opNumberInfo, statisticalReportParam);

			opNumberInfo.setOpRatioText(opRatioText);

			String thirdForthOpRatioText = ReportTemplate.getThirdForthOpRatioText(opNumberInfo,
					statisticalReportParam);
			opNumberInfo.setThirdForthOpRatioText(thirdForthOpRatioText);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/", guid + ".json");
			if (jsonMap != null) {
				Map<String, Object> opNumberInfoMap = MapUtils.getMap(jsonMap, "opNumberInfo");
				if (MapUtils.isNotEmpty(opNumberInfoMap)) {
					String opRateNote = MapUtils.getString(opNumberInfoMap, "opRateNote");
					map.put("opRateNote",
							StringUtils.isEmpty(opRateNote) ? null : opRateNote.replaceAll("\n", "<w:br/>"));
					String thirdForthOpRatioNote = MapUtils.getString(opNumberInfoMap, "thirdForthOpRatioNote");
					map.put("thirdForthOpRatioNote", StringUtils.isEmpty(thirdForthOpRatioNote) ? null
							: thirdForthOpRatioNote.replaceAll("\n", "<w:br/>"));
				}
			}

			map.put("opRatioText", opRatioText.replaceAll("\n", "<w:br/>"));
			map.put("thirdForthOpRatioText", thirdForthOpRatioText.replaceAll("\n", "<w:br/>"));
			map.put("img1", opPrecentImage);
			map.put("date", statisticalReportParam.getStatics1Name());
			map.put("img2", opRateImage);
			map.put("img3", opHolidayImage);
			WordUtil.exportTemplateWord(request, response, map, "opNum.ftl", "手术及操作人次数");
		}

	}

	// ===================================================手术及操作人次数end======================================================================

	// ===================================================各科室出院患者统计指标start======================================================================

	@RequestMapping("/eachOutDeptInfoPage")
	public String eachOutDeptInfoPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("bed_index_module");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		User user = (User) request.getSession().getAttribute("user");
		try {

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			Map<String, Object> outHospStatisIndexInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				outHospStatisIndexInfoMap = MapUtils.getMap(jsonMap, "outHospStatisIndexInfo");
				if (MapUtils.isNotEmpty(outHospStatisIndexInfoMap)) {
					model.addAttribute("outHospStatisIndexInfo", outHospStatisIndexInfoMap);
				}
			}

			if (MapUtils.isEmpty(outHospStatisIndexInfoMap)) {
				OutHospStatisIndexInfo outHospStatisIndexInfo = medicalService
						.getOutHospStatisIndexInfo(statisticalReportParam, user.getOrgCode());
				String text = ReportTemplate.getOutHospStatisIndexText(outHospStatisIndexInfo, statisticalReportParam);
				outHospStatisIndexInfo.setText(text);
				model.addAttribute("outHospStatisIndexInfo", outHospStatisIndexInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return "query/eachOutDeptInfoPage.page";
	}

	@GetMapping("/outPatientEachDeptInfo")
	public String outPatientEachDeptInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			Map<String, Object> outHospStatisIndexInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				outHospStatisIndexInfoMap = MapUtils.getMap(jsonMap, "outHospStatisIndexInfo");
				if (MapUtils.isNotEmpty(outHospStatisIndexInfoMap)) {
					model.addAttribute("outHospStatisIndexInfo", outHospStatisIndexInfoMap);
				}
			}

			if (MapUtils.isEmpty(outHospStatisIndexInfoMap)) {
				OutHospStatisIndexInfo outHospStatisIndexInfo = medicalService
						.getOutHospStatisIndexInfo(statisticalReportParam, user.getOrgCode());
				String text = ReportTemplate.getOutHospStatisIndexText(outHospStatisIndexInfo, statisticalReportParam);
				outHospStatisIndexInfo.setText(text);
				model.addAttribute("outHospStatisIndexInfo", outHospStatisIndexInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/outPatientEachDeptInfo";
	}

	@ResponseBody
	@PostMapping("/saveOutPatientEachDeptInfo")
	public Result saveOutPatientEachDeptInfo(Model model, HttpServletRequest request) {
		Result result = null;
		User user = (User) request.getSession().getAttribute("user");
		String note = request.getParameter("note");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");

			OutHospStatisIndexInfo outHospStatisIndexInfo = medicalService
					.getOutHospStatisIndexInfo(statisticalReportParam, user.getOrgCode());

			String text = ReportTemplate.getOutHospStatisIndexText(outHospStatisIndexInfo, statisticalReportParam);
			outHospStatisIndexInfo.setText(text);
			outHospStatisIndexInfo.setNote(StringUtils.isEmpty(note) ? null : note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("outHospStatisIndexInfo", outHospStatisIndexInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			result = new Result(true, "各科室出院患者统计指标保存成功!");

		} catch (Exception e) {
			result = new Result(false, "各科室出院患者统计指标保存失败!");
			e.printStackTrace();
		}

		return result;
	}

	@ResponseBody
	@RequestMapping(value = "exportOutEachDeptWord")
	public void exportOutEachDeptWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");

		// 获取base64图片信息

		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		OutHospStatisIndexInfo outHospStatisIndexInfo = medicalService.getOutHospStatisIndexInfo(statisticalReportParam,
				user.getOrgCode());

		String text = ReportTemplate.getOutHospStatisIndexText(outHospStatisIndexInfo, statisticalReportParam);

		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		if (jsonMap != null) {
			@SuppressWarnings("unchecked")
			Map<String, Object> outHospStatisIndexInfoMap = MapUtils.getMap(jsonMap, "outHospStatisIndexInfo");
			if (MapUtils.isNotEmpty(outHospStatisIndexInfoMap)) {
				String note = MapUtils.getString(outHospStatisIndexInfoMap, "note");
				map.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			}
		}

		map.put("text", text.replaceAll("\n", "<w:br/>"));
		map.put("date", statisticalReportParam.getStatics1Name());

		map.put("outHospStatisIndexRecordList", outHospStatisIndexInfo.getOutHospStatisIndexRecordList());

		WordUtil.exportTemplateWord(request, response, map, "eachDeptStatis.ftl", "各科室出院患者统计指标");

	}

	// ===================================================各科室出院患者统计指标end======================================================================

	/**
	 * 导出费用信息
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "exportCostFeeWord")
	public void exportCostFeeWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		String method = request.getParameter("method");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		// 获取base64图片信息
		if ("getImage".equals(method)) {
			String image = request.getParameter("image");
			costFeeImage = getBase64Image(image);
			// 导出数据
		} else {

			String costFeeNote = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				Map<String, Object> costFeeInfoMap = MapUtils.getMap(jsonMap, "costFeeInfo");
				if (MapUtils.isNotEmpty(costFeeInfoMap)) {
					costFeeNote = MapUtils.getString(costFeeInfoMap, "costFeeNote");
				}
			}

			CostFeeInfo costFeeInfo = medicalService.getCostFeeInfo(statisticalReportParam, user.getOrgCode());
			String costText = ReportTemplate.getCostInfoText(costFeeInfo, statisticalReportParam);
			map.put("costFeeNote", costFeeNote.replaceAll("\n", "<w:br/>"));
			map.put("costFee", costText.replaceAll("\n", "<w:br/>"));
			map.put("costFeeImage", costFeeImage);
			map.put("date", statisticalReportParam.getStatics1Name());
			WordUtil.exportTemplateWord(request, response, map, "costFee.ftl", "住院费用指标");
		}

	}

	@ResponseBody
	@RequestMapping(value = "exportDiagTop20Word")
	public void exportDiagTop20Word(HttpServletRequest request, HttpServletResponse response) throws Exception {
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		User user = (User) request.getSession().getAttribute("user");
		// 获取base64图片信息
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
		DiagTop20OrderInfo diagTop20OrderInfo = medicalService.getDiagOrderTop20(statisticalReportParam, user.getOrgCode(), null);

		List<Top20DTO> top20DTOList = new LinkedList<>();
		List<TopOrderRecord> list1 = diagTop20OrderInfo.getTop20diagOrderRecords();
		List<TopOrderRecord> list2 = diagTop20OrderInfo.getPreMonthtop20diagOrderRecords();
		List<TopOrderRecord> list3 = diagTop20OrderInfo.getLastYeartop20diagOrderRecords();
		Top20DTO top20DTO = null;
		for (int i = 0; i < list1.size(); i++) {
			TopOrderRecord record1 = list1.get(i);
			TopOrderRecord record2 = list2.get(i);
			TopOrderRecord record3 = list3.get(i);
			top20DTO = new Top20DTO();

			top20DTO.setTopOrder(record1.getTopOrder() == null ? "" : record1.getTopOrder());
			top20DTO.setDiagCode1(record1.getDiagCode() == null ? "" : record1.getDiagCode());
			top20DTO.setDiagName1(record1.getDiagName() == null ? "" : record1.getDiagName());
			top20DTO.setDiagNum1(record1.getDiagNum());
			top20DTO.setAvgInHospDays1(record1.getAvgInHospDays());
			top20DTO.setAvgCostFee1(record1.getAvgCostFee());

			top20DTO.setDiagCode2(record2.getDiagCode());
			top20DTO.setDiagName2(record2.getDiagName());
			top20DTO.setDiagNum2(record2.getDiagNum());
			top20DTO.setAvgInHospDays2(record2.getAvgInHospDays());
			top20DTO.setAvgCostFee2(record2.getAvgCostFee());

			top20DTO.setDiagCode3(record3.getDiagCode());
			top20DTO.setDiagName3(record3.getDiagName());
			top20DTO.setDiagNum3(record3.getDiagNum());
			top20DTO.setAvgInHospDays3(record3.getAvgInHospDays());
			top20DTO.setAvgCostFee3(record3.getAvgCostFee());

			if (record1.getTopOrder().equals("合计")) {
				top20DTO.setTopOrder("");
				top20DTO.setDiagCode1("合计");
			}

			System.out.println(top20DTO);

			top20DTOList.add(top20DTO);
		}

		Map<String, Object> map = new HashMap<>();

		String diagTop20Text = ReportTemplate.getDiagTop20InfoText(diagTop20OrderInfo, statisticalReportParam);

		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");
		if (MapUtils.isNotEmpty(jsonMap)) {
			Map<String, Object> diagTop20OrderInfoMap = MapUtils.getMap(jsonMap, "diagTop20OrderInfo");
			if (MapUtils.isNotEmpty(diagTop20OrderInfoMap)) {
				String top20OrderNote = MapUtils.getString(diagTop20OrderInfoMap, "top20OrderNote");
				if (StringUtils.isNotEmpty(top20OrderNote)) {
					map.put("top20OrderNote", top20OrderNote.replaceAll("\n", "<w:br/>"));
				}

			}
		}

		map.put("top20OrderText", diagTop20Text.replaceAll("\n", "<w:br/>"));
		map.put("statisticalReportParam", statisticalReportParam);

		map.put("diagTop20List", top20DTOList);

		WordUtil.exportTemplateWord(request, response, map, "diagTop20.ftl", "全院疾病顺位");

	}

	/**
	 * 处理echarts传递来的base64图片信息
	 * 
	 * @param image
	 * @return
	 */
	public String getBase64Image(String image) {
		String base64 = image.replaceAll(" ", "+");
		// 数据中： ...
		// 在"base64,"之后的才是图片信息
		String[] arr = base64.split("base64,");
		return arr[1];
	}

//	@ResponseBody
//	@RequestMapping(value = "exportAllWord")
//	public void exportAllWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
//		Map<String, Object> map = new HashMap<>();
//		User user = (User) request.getSession().getAttribute("user");
//		String params = request.getParameter("month");
//		String guid = MD5.md5(params);
//		// 获取base64图片信息
//		String year = params.split("-")[0];
//		String month = params.split("-")[1];
//		map.put("year", year);
//		map.put("month", month);
//
//		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/", guid + ".json");
//
//		Map<String, Object> outPatientVisitInfoMap = MapUtils.getMap(jsonMap, "outPatientVisitInfo");
//		if (MapUtils.isNotEmpty(outPatientVisitInfoMap)) {
//			Map<String, String> map1 = new HashMap<>();
//			String summary = MapUtils.getString(outPatientVisitInfoMap, "summary");
//			map1.put("summary", StringUtils.isEmpty(summary) ? null : summary.replaceAll("\n", "<w:br/>"));
//
//			String outPatientVisitText = MapUtils.getString(outPatientVisitInfoMap, "outPatientVisitText");
//			map1.put("outPatientVisitText",
//					StringUtils.isEmpty(outPatientVisitText) ? null : outPatientVisitText.replaceAll("\n", "<w:br/>"));
//
//			String note = MapUtils.getString(outPatientVisitInfoMap, "note");
//			map1.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
//
//			map1.put("outPatientVisitImageBase64",
//					MapUtils.getString(outPatientVisitInfoMap, "outPatientVisitImageBase64"));
//
//			map.put("outPatientVisitInfo", map1);
//		}
//
//		Map<String, Object> bedIndexInfoMap = MapUtils.getMap(jsonMap, "bedIndexInfo");
//		if (MapUtils.isNotEmpty(bedIndexInfoMap)) {
//			Map<String, Object> map2 = new HashMap<>();
//			String bedIndexText = MapUtils.getString(bedIndexInfoMap, "bedIndexText");
//			map2.put("bedIndexText",
//					StringUtils.isEmpty(bedIndexText) ? null : bedIndexText.replaceAll("\n", "<w:br/>"));
//			String bedIndexNote = MapUtils.getString(bedIndexInfoMap, "bedIndexNote");
//			map2.put("bedIndexNote",
//					StringUtils.isEmpty(bedIndexNote) ? null : bedIndexNote.replaceAll("\n", "<w:br/>"));
//			map2.put("bedIndexRecordList", MapUtils.getObject(bedIndexInfoMap, "bedIndexRecordList"));
//
//			map.put("bedIndexInfo", map2);
//		}
//
//		Map<String, Object> outNumDeathRateInfoMap = MapUtils.getMap(jsonMap, "outNumDeathRateInfo");
//		if (MapUtils.isNotEmpty(outNumDeathRateInfoMap)) {
//			Map<String, Object> map3 = new HashMap<>();
//			String outDeathRateText = MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateText");
//			map3.put("outNumDeathRateText",
//					StringUtils.isEmpty(outDeathRateText) ? null : outDeathRateText.replaceAll("\n", "<w:br/>"));
//			String note = MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateNote");
//			map3.put("outNumDeathRateNote", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
//			map3.put("outNumDeathRateBase64Img",
//					MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateBase64Img"));
//
//			map.put("outNumDeathRateInfo", map3);
//		}
//
//		Map<String, Object> avgInHospDaysInfoMap = MapUtils.getMap(jsonMap, "avgInHospDaysInfo");
//		if (MapUtils.isNotEmpty(avgInHospDaysInfoMap)) {
//			Map<String, Object> map4 = new HashMap<>();
//			String text = MapUtils.getString(avgInHospDaysInfoMap, "text");
//			map4.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
//			String note = MapUtils.getString(avgInHospDaysInfoMap, "note");
//			map4.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
//
//			map.put("avgInHospDaysInfo", map4);
//		}
//
//		Map<String, Object> opNumberInfoMap = MapUtils.getMap(jsonMap, "opNumberInfo");
//		if (MapUtils.isNotEmpty(opNumberInfoMap)) {
//			Map<String, Object> map5 = new HashMap<>();
//			String opRatioText = MapUtils.getString(opNumberInfoMap, "opRatioText");
//			map5.put("opRatioText", StringUtils.isEmpty(opRatioText) ? null : opRatioText.replaceAll("\n", "<w:br/>"));
//			String opRateNote = MapUtils.getString(opNumberInfoMap, "opRateNote");
//			map5.put("opRateNote", StringUtils.isEmpty(opRateNote) ? null : opRateNote.replaceAll("\n", "<w:br/>"));
//
//			String thirdForthOpRatioText = MapUtils.getString(opNumberInfoMap, "thirdForthOpRatioText");
//			map5.put("thirdForthOpRatioText", StringUtils.isEmpty(thirdForthOpRatioText) ? null
//					: thirdForthOpRatioText.replaceAll("\n", "<w:br/>"));
//			String thirdForthOpRatioNote = MapUtils.getString(opNumberInfoMap, "thirdForthOpRatioNote");
//			map5.put("thirdForthOpRatioNote", StringUtils.isEmpty(thirdForthOpRatioNote) ? null
//					: thirdForthOpRatioNote.replaceAll("\n", "<w:br/>"));
//
//			String echart1Image = MapUtils.getString(opNumberInfoMap, "echart1Image");
//			map5.put("echart1Image", StringUtils.isEmpty(echart1Image) ? null : getBase64Image(echart1Image));
//			String echart2Image = MapUtils.getString(opNumberInfoMap, "echart2Image");
//			map5.put("echart2Image", StringUtils.isEmpty(echart2Image) ? null : getBase64Image(echart2Image));
//			String echart3Image = MapUtils.getString(opNumberInfoMap, "echart3Image");
//			map5.put("echart3Image", StringUtils.isEmpty(echart3Image) ? null : getBase64Image(echart3Image));
//			map.put("opNumberInfo", map5);
//		}
//
//		Map<String, Object> costFeeInfoMap = MapUtils.getMap(jsonMap, "costFeeInfo");
//		if (MapUtils.isNotEmpty(costFeeInfoMap)) {
//			Map<String, Object> map6 = new HashMap<>();
//			String costText = MapUtils.getString(costFeeInfoMap, "costText");
//			map6.put("costText", StringUtils.isEmpty(costText) ? null : costText.replaceAll("\n", "<w:br/>"));
//			String costFeeNote = MapUtils.getString(costFeeInfoMap, "costFeeNote");
//			map6.put("costFeeNote", StringUtils.isEmpty(costFeeNote) ? null : costFeeNote.replaceAll("\n", "<w:br/>"));
//
//			map6.put("costFeeBase64Image", MapUtils.getString(costFeeInfoMap, "costFeeBase64Image"));
//
//			map.put("costFeeInfo", map6);
//		}
//
//		Map<String, Object> outHospStatisIndexInfoMap = MapUtils.getMap(jsonMap, "outHospStatisIndexInfo");
//		if (MapUtils.isNotEmpty(outHospStatisIndexInfoMap)) {
//			Map<String, Object> map7 = new HashMap<>();
//			String text = MapUtils.getString(outHospStatisIndexInfoMap, "text");
//			map7.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
//			String note = MapUtils.getString(outHospStatisIndexInfoMap, "note");
//			map7.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
//
//			map7.put("outHospStatisIndexRecordList",
//					MapUtils.getObject(outHospStatisIndexInfoMap, "outHospStatisIndexRecordList"));
//			map.put("outHospStatisIndexInfo", map7);
//		}
//
//		Map<String, Object> diagTop20OrderInfoMap = MapUtils.getMap(jsonMap, "diagTop20OrderInfo");
//		if (MapUtils.isNotEmpty(diagTop20OrderInfoMap)) {
//			Map<String, Object> map8 = new HashMap<>();
//			String top20OrderText = MapUtils.getString(diagTop20OrderInfoMap, "top20OrderText");
//			map8.put("top20OrderText",
//					StringUtils.isEmpty(top20OrderText) ? null : top20OrderText.replaceAll("\n", "<w:br/>"));
//			String top20OrderNote = MapUtils.getString(diagTop20OrderInfoMap, "top20OrderNote");
//			map8.put("top20OrderNote",
//					StringUtils.isEmpty(top20OrderNote) ? null : top20OrderNote.replaceAll("\n", "<w:br/>"));
//			map8.put("top20diagOrderRecords", MapUtils.getObject(diagTop20OrderInfoMap, "top20diagOrderRecords"));
//			map.put("diagTop20OrderInfo", map8);
//		}
//
//		Map<String, Object> diagTop10DeptInfoMap = MapUtils.getMap(jsonMap, "diagTop10DeptInfo");
//		if (MapUtils.isNotEmpty(diagTop10DeptInfoMap)) {
//			List<Map<String, Object>> diagTop10DeptRecordMaps = (List<Map<String, Object>>) MapUtils
//					.getObject(diagTop10DeptInfoMap, "diagTop10DeptRecord");
//			if (CollectionUtils.isNotEmpty(diagTop10DeptRecordMaps)) {
//				String diagTop10DeptRecordJson = JsonUtil.objectToJson(diagTop10DeptRecordMaps);
//				List<DiagTop10DeptRecord> diagTop10DeptRecordList = JsonUtil.jsonToList(diagTop10DeptRecordJson,
//						DiagTop10DeptRecord.class);
//				List<Top10DTO> top10DTOList = getDiagTop10PTO(diagTop10DeptRecordList);
//				if (CollectionUtils.isNotEmpty(top10DTOList)) {
//					/*
//					 * Map<String, Object> diagTop10Map = new LinkedHashMap<>();
//					 * Collections.sort(top10DTOList, new Comparator<Top10DTO>() {
//					 * 
//					 * @Override public int compare(Top10DTO o1, Top10DTO o2) {
//					 * 
//					 * return o2.getNum() - o1.getNum(); } }); int index = 0; for (Top10DTO top10dto
//					 * : top10DTOList) { diagTop10Map.put("list" + index, top10dto.getList());
//					 * index++;
//					 * 
//					 * }
//					 * 
//					 * map.put("diagTop10Map", diagTop10Map);
//					 */}
//
//			}
//		}
//
//		Map<String, Object> opsTop20InfoMap = MapUtils.getMap(jsonMap, "opsTop20Info");
//		if (MapUtils.isNotEmpty(opsTop20InfoMap)) {
//			Map<String, Object> map9 = new HashMap<>();
//			String operationTop20Text = MapUtils.getString(opsTop20InfoMap, "operationTop20Text");
//			map9.put("operationTop20Text",
//					StringUtils.isEmpty(operationTop20Text) ? null : operationTop20Text.replaceAll("\n", "<w:br/>"));
//			String note = MapUtils.getString(diagTop20OrderInfoMap, "note");
//			map9.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
//			map9.put("topOrderRecords", MapUtils.getObject(opsTop20InfoMap, "topOrderRecords"));
//			map.put("opsTop20Info", map9);
//		}
//
//		Map<String, Object> opsTop10InfoMap = MapUtils.getMap(jsonMap, "opsTop10Info");
//
//		if (MapUtils.isNotEmpty(opsTop10InfoMap)) {
//			/*
//			 * List<Map<String, Object>> opsTop10Maps = (List<Map<String, Object>>)
//			 * MapUtils.getObject(opsTop10InfoMap, "diagTop10DeptRecord"); if
//			 * (CollectionUtils.isNotEmpty(opsTop10Maps)) { String opsTop10RecordJson =
//			 * JsonUtil.objectToJson(opsTop10Maps); List<DiagTop10DeptRecord>
//			 * diagTop10DeptRecordList = JsonUtil.jsonToList(opsTop10RecordJson,
//			 * DiagTop10DeptRecord.class); List<Top10DTO> top10DTOList =
//			 * getDiagTop10PTO(diagTop10DeptRecordList); if
//			 * (CollectionUtils.isNotEmpty(top10DTOList)) { Map<String, Object> opsTop10Map
//			 * = new LinkedHashMap<>(); Collections.sort(top10DTOList, new
//			 * Comparator<Top10DTO>() {
//			 * 
//			 * @Override public int compare(Top10DTO o1, Top10DTO o2) {
//			 * 
//			 * return o2.getNum() - o1.getNum(); } }); int index = 0; for (Top10DTO top10dto
//			 * : top10DTOList) { opsTop10Map.put("list" + index, top10dto.getList());
//			 * index++;
//			 * 
//			 * }
//			 * 
//			 * map.put("opsTop10Map", opsTop10Map); }
//			 * 
//			 * }
//			 */}
//
//		Map<String, Object> deathReasonInfoMap = MapUtils.getMap(jsonMap, "deathReasonInfo");
//
//		if (MapUtils.isNotEmpty(deathReasonInfoMap)) {
//			Map<String, Object> map10 = new HashMap<>();
//			String top20OrderText = MapUtils.getString(deathReasonInfoMap, "top20OrderText");
//			map10.put("top20OrderText",
//					StringUtils.isEmpty(top20OrderText) ? null : top20OrderText.replaceAll("\n", "<w:br/>"));
//			String top20OrderNote = MapUtils.getString(deathReasonInfoMap, "top20OrderNote");
//			map10.put("top20OrderNote",
//					StringUtils.isEmpty(top20OrderNote) ? null : top20OrderNote.replaceAll("\n", "<w:br/>"));
//			map10.put("top20diagOrderRecords", MapUtils.getObject(deathReasonInfoMap, "top20diagOrderRecords"));
//			map.put("deathReasonInfo", map10);
//		}
//
//		WordUtil.exportTemplateWord(request, response, map, "all.ftl", "统计指标综合分析报告");
//
//	}

	@ResponseBody
	@RequestMapping(value = "exportAllWord")
	public void exportAllWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		map.put("statisticalReportParam", statisticalReportParam);
		
		map.put("date", DateUtil.dateFormat("yyyy年MM月dd日", new Date()));

		Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
				statisticalReportParam.getOnlyId() + ".json");

		Map<String, Object> outPatientVisitInfoMap = MapUtils.getMap(jsonMap, "outPatientVisitInfo");
		if (MapUtils.isNotEmpty(outPatientVisitInfoMap)) {
			Map<String, String> map1 = new HashMap<>();
			String summary = MapUtils.getString(outPatientVisitInfoMap, "summary");
			map1.put("summary", StringUtils.isEmpty(summary) ? null : summary.replaceAll("\n", "<w:br/>"));

			String outPatientVisitText = MapUtils.getString(outPatientVisitInfoMap, "outPatientVisitText");
			map1.put("outPatientVisitText",
					StringUtils.isEmpty(outPatientVisitText) ? null : outPatientVisitText.replaceAll("\n", "<w:br/>"));

			String note = MapUtils.getString(outPatientVisitInfoMap, "note");
			map1.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));

			map1.put("outPatientVisitImageBase64",
					MapUtils.getString(outPatientVisitInfoMap, "outPatientVisitImageBase64"));

			map.put("outPatientVisitInfo", map1);
		}

		Map<String, Object> bedIndexInfoMap = MapUtils.getMap(jsonMap, "bedIndexInfo");
		if (MapUtils.isNotEmpty(bedIndexInfoMap)) {
			Map<String, Object> map2 = new HashMap<>();
			String bedIndexText = MapUtils.getString(bedIndexInfoMap, "bedIndexText");
			map2.put("bedIndexText",
					StringUtils.isEmpty(bedIndexText) ? null : bedIndexText.replaceAll("\n", "<w:br/>"));
			String bedIndexNote = MapUtils.getString(bedIndexInfoMap, "bedIndexNote");
			map2.put("bedIndexNote",
					StringUtils.isEmpty(bedIndexNote) ? null : bedIndexNote.replaceAll("\n", "<w:br/>"));
			map2.put("bedIndexRecordList", MapUtils.getObject(bedIndexInfoMap, "bedIndexRecordList"));

			map.put("bedIndexInfo", map2);
		}

		Map<String, Object> outNumDeathRateInfoMap = MapUtils.getMap(jsonMap, "outNumDeathRateInfo");
		if (MapUtils.isNotEmpty(outNumDeathRateInfoMap)) {
			Map<String, Object> map3 = new HashMap<>();
			String outDeathRateText = MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateText");
			map3.put("outNumDeathRateText",
					StringUtils.isEmpty(outDeathRateText) ? null : outDeathRateText.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateNote");
			map3.put("outNumDeathRateNote", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map3.put("outNumDeathRateBase64Img",
					MapUtils.getString(outNumDeathRateInfoMap, "outNumDeathRateBase64Img"));

			map.put("outNumDeathRateInfo", map3);
		}

		Map<String, Object> avgInHospDaysInfoMap = MapUtils.getMap(jsonMap, "avgInHospDaysInfo");
		if (MapUtils.isNotEmpty(avgInHospDaysInfoMap)) {
			Map<String, Object> map4 = new HashMap<>();
			String text = MapUtils.getString(avgInHospDaysInfoMap, "text");
			map4.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(avgInHospDaysInfoMap, "note");
			map4.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));

			map.put("avgInHospDaysInfo", map4);
		}

		Map<String, Object> opNumberInfoMap = MapUtils.getMap(jsonMap, "opNumberInfo");
		if (MapUtils.isNotEmpty(opNumberInfoMap)) {
			Map<String, Object> map5 = new HashMap<>();
			String opRatioText = MapUtils.getString(opNumberInfoMap, "opRatioText");
			map5.put("opRatioText", StringUtils.isEmpty(opRatioText) ? null : opRatioText.replaceAll("\n", "<w:br/>"));
			String opRateNote = MapUtils.getString(opNumberInfoMap, "opRateNote");
			map5.put("opRateNote", StringUtils.isEmpty(opRateNote) ? null : opRateNote.replaceAll("\n", "<w:br/>"));

			String thirdForthOpRatioText = MapUtils.getString(opNumberInfoMap, "thirdForthOpRatioText");
			map5.put("thirdForthOpRatioText", StringUtils.isEmpty(thirdForthOpRatioText) ? null
					: thirdForthOpRatioText.replaceAll("\n", "<w:br/>"));
			String thirdForthOpRatioNote = MapUtils.getString(opNumberInfoMap, "thirdForthOpRatioNote");
			map5.put("thirdForthOpRatioNote", StringUtils.isEmpty(thirdForthOpRatioNote) ? null
					: thirdForthOpRatioNote.replaceAll("\n", "<w:br/>"));

			String echart1Image = MapUtils.getString(opNumberInfoMap, "echart1Image");
			map5.put("echart1Image", StringUtils.isEmpty(echart1Image) ? null : getBase64Image(echart1Image));
			String echart2Image = MapUtils.getString(opNumberInfoMap, "echart2Image");
			map5.put("echart2Image", StringUtils.isEmpty(echart2Image) ? null : getBase64Image(echart2Image));
			String echart3Image = MapUtils.getString(opNumberInfoMap, "echart3Image");
			map5.put("echart3Image", StringUtils.isEmpty(echart3Image) ? null : getBase64Image(echart3Image));
			map.put("opNumberInfo", map5);
		}

		Map<String, Object> costFeeInfoMap = MapUtils.getMap(jsonMap, "costFeeInfo");
		if (MapUtils.isNotEmpty(costFeeInfoMap)) {
			Map<String, Object> map6 = new HashMap<>();
			String costText = MapUtils.getString(costFeeInfoMap, "costText");
			map6.put("costText", StringUtils.isEmpty(costText) ? null : costText.replaceAll("\n", "<w:br/>"));
			String costFeeNote = MapUtils.getString(costFeeInfoMap, "costFeeNote");
			map6.put("costFeeNote", StringUtils.isEmpty(costFeeNote) ? null : costFeeNote.replaceAll("\n", "<w:br/>"));

			map6.put("costFeeBase64Image", MapUtils.getString(costFeeInfoMap, "costFeeBase64Image"));

			map.put("costFeeInfo", map6);
		}

		Map<String, Object> outHospStatisIndexInfoMap = MapUtils.getMap(jsonMap, "outHospStatisIndexInfo");
		if (MapUtils.isNotEmpty(outHospStatisIndexInfoMap)) {
			Map<String, Object> map7 = new HashMap<>();
			String text = MapUtils.getString(outHospStatisIndexInfoMap, "text");
			map7.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(outHospStatisIndexInfoMap, "note");
			map7.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));

			map7.put("outHospStatisIndexRecordList",
					MapUtils.getObject(outHospStatisIndexInfoMap, "outHospStatisIndexRecordList"));
			map.put("outHospStatisIndexInfo", map7);
		}

		Map<String, Object> diagTop20OrderMap = MapUtils.getMap(jsonMap, "diagTop20OrderInfo");
		if (MapUtils.isNotEmpty(diagTop20OrderMap)) {
			Map<String, Object> map8 = new HashMap<>();

			String text = MapUtils.getString(diagTop20OrderMap, "top20OrderText");
			map8.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(diagTop20OrderMap, "top20OrderNote");
			map8.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map8.put("list", MapUtils.getObject(diagTop20OrderMap, "top20DTOList"));

			map.put("diagTop20OrderInfo", map8);

		}

		Map<String, Object> diagTop10DeptInfoMap = MapUtils.getMap(jsonMap, "diagTop10DeptInfo");
		if (MapUtils.isNotEmpty(diagTop10DeptInfoMap)) {
			Map<String, Object> map9 = new HashMap<>();

			String note = MapUtils.getString(diagTop10DeptInfoMap, "note");
			map9.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map9.put("list", MapUtils.getObject(diagTop10DeptInfoMap, "diagTop20DTOList"));

			map.put("diagTop10DeptInfo", map9);

		}

		Map<String, Object> deathReasonMap = MapUtils.getMap(jsonMap, "deathReasonInfo");
		if (MapUtils.isNotEmpty(deathReasonMap)) {
			Map<String, Object> map10 = new HashMap<>();

			String text = MapUtils.getString(deathReasonMap, "top20OrderText");
			map10.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(deathReasonMap, "top20OrderNote");
			map10.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map10.put("list", MapUtils.getObject(deathReasonMap, "top20DTOList"));

			map.put("deathReasonInfo", map10);

		}

		Map<String, Object> opsTop20Map = MapUtils.getMap(jsonMap, "opsTop20Info");
		if (MapUtils.isNotEmpty(opsTop20Map)) {
			Map<String, Object> map11 = new HashMap<>();

			String text = MapUtils.getString(opsTop20Map, "operationTop20Text");
			map11.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(opsTop20Map, "note");
			map11.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map11.put("list", MapUtils.getObject(opsTop20Map, "top20DTOList"));

			map.put("opsTop20Info", map11);

		}

		Map<String, Object> opsTop10Map = MapUtils.getMap(jsonMap, "opsTop10Info");
		if (MapUtils.isNotEmpty(opsTop10Map)) {
			Map<String, Object> map12 = new HashMap<>();
			String note = MapUtils.getString(opsTop10Map, "note");
			map12.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map12.put("list", MapUtils.getObject(opsTop10Map, "diagTop20DTOList"));
			map.put("opsTop10Info", map12);
		}

		Map<String, Object> qcBackMap = MapUtils.getMap(jsonMap, "qcBackInfo");
		if (MapUtils.isNotEmpty(qcBackMap)) {
			Map<String, Object> map13 = new HashMap<>();
			String text = MapUtils.getString(qcBackMap, "text");
			map13.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(qcBackMap, "note");
			map13.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map13.put("list", MapUtils.getObject(qcBackMap, "qcBackRecordList"));
			map.put("qcBackInfo", map13);
		}

		Map<String, Object> qcAcquiredMap = MapUtils.getMap(jsonMap, "qcAcquiredInfo");
		if (MapUtils.isNotEmpty(qcAcquiredMap)) {
			Map<String, Object> map14 = new HashMap<>();
			String text = MapUtils.getString(qcAcquiredMap, "text");
			map14.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(qcAcquiredMap, "note");
			map14.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map14.put("list", MapUtils.getObject(qcAcquiredMap, "qcAcquiredList"));
			map.put("qcAcquiredInfo", map14);
		}

		Map<String, Object> major20DiagMap = MapUtils.getMap(jsonMap, "major20DiagInfo");
		if (MapUtils.isNotEmpty(major20DiagMap)) {
			Map<String, Object> map15 = new HashMap<>();
			String text = MapUtils.getString(major20DiagMap, "text");
			map15.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(major20DiagMap, "note");
			map15.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map15.put("list", MapUtils.getObject(major20DiagMap, "list"));
			map.put("major20DiagInfo", map15);
		}

		Map<String, Object> major20OperationMap = MapUtils.getMap(jsonMap, "major20OperationInfo");
		if (MapUtils.isNotEmpty(major20OperationMap)) {
			Map<String, Object> map16 = new HashMap<>();
			String text = MapUtils.getString(major20OperationMap, "text");
			map16.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(major20OperationMap, "note");
			map16.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map16.put("list", MapUtils.getObject(major20OperationMap, "list"));
			map.put("major20OperationInfo", map16);
		}

		// 门诊患者满意度
		Map<String, Object> outpatientSatisfactionMap = MapUtils.getMap(jsonMap, "outpatientSatisfactionInfo");
		if (MapUtils.isNotEmpty(outpatientSatisfactionMap)) {
			Map<String, Object> map17 = new HashMap<>();
			String text = MapUtils.getString(outpatientSatisfactionMap, "statistionText");
			map17.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(outpatientSatisfactionMap, "statistionNote");
			map17.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map17.put("list", MapUtils.getObject(outpatientSatisfactionMap, "outpatientSatisfactionRecords"));
			map.put("outpatientSatisfactionInfo", map17);
		}

		// 门诊患者满意度分析
		Map<String, Object> outSatisContrastAnalysisMap = MapUtils.getMap(jsonMap, "outSatisContrastAnalysisInfo");
		if (MapUtils.isNotEmpty(outSatisContrastAnalysisMap)) {
			Map<String, Object> map18 = new HashMap<>();
			String note = MapUtils.getString(outSatisContrastAnalysisMap, "analysisNote");
			map18.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map18.put("list", MapUtils.getObject(outSatisContrastAnalysisMap, "outSatisContrastAnalysisRecord"));
			map.put("outSatisContrastAnalysisInfo", map18);
		}
		
		// 16个重点肿瘤非手术治疗相关指标
		Map<String, Object> majorTumourNonOpMap = MapUtils.getMap(jsonMap, "majorTumourNonOpInfo");
		if (MapUtils.isNotEmpty(majorTumourNonOpMap)) {
			Map<String, Object> map19 = new HashMap<>();
			String text = MapUtils.getString(majorTumourNonOpMap, "text");
			map19.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(majorTumourNonOpMap, "note");
			map19.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map19.put("list", MapUtils.getObject(majorTumourNonOpMap, "list"));
			map.put("majorTumourNonOpInfo", map19);
		}
		
		// 14个重点恶性肿瘤住院手术治疗相关指标
		Map<String, Object> majorTumourOpMap = MapUtils.getMap(jsonMap, "majorTumourOpInfo");
		if (MapUtils.isNotEmpty(majorTumourOpMap)) {
			Map<String, Object> map19 = new HashMap<>();
			String text = MapUtils.getString(majorTumourOpMap, "text");
			map19.put("text", StringUtils.isEmpty(text) ? null : text.replaceAll("\n", "<w:br/>"));
			String note = MapUtils.getString(majorTumourOpMap, "note");
			map19.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
			map19.put("list", MapUtils.getObject(majorTumourOpMap, "list"));
			map.put("majorTumourOpInfo", map19);
		}
		
		
		

//		Map<String, Object> diagTop20OrderInfoMap = MapUtils.getMap(jsonMap, "diagTop20OrderInfo");
//		if (MapUtils.isNotEmpty(diagTop20OrderInfoMap)) {
//			Map<String, Object> map8 = new HashMap<>();
//			String top20OrderText = MapUtils.getString(diagTop20OrderInfoMap, "top20OrderText");
//			map8.put("top20OrderText",
//					StringUtils.isEmpty(top20OrderText) ? null : top20OrderText.replaceAll("\n", "<w:br/>"));
//			String top20OrderNote = MapUtils.getString(diagTop20OrderInfoMap, "top20OrderNote");
//			map8.put("top20OrderNote",
//					StringUtils.isEmpty(top20OrderNote) ? null : top20OrderNote.replaceAll("\n", "<w:br/>"));
//			map8.put("top20diagOrderRecords", MapUtils.getObject(diagTop20OrderInfoMap, "top20diagOrderRecords"));
//			map.put("diagTop20OrderInfo", map8);
//		}
//
//		Map<String, Object> diagTop10DeptInfoMap = MapUtils.getMap(jsonMap, "diagTop10DeptInfo");
//		if (MapUtils.isNotEmpty(diagTop10DeptInfoMap)) {
//			List<Map<String, Object>> diagTop10DeptRecordMaps = (List<Map<String, Object>>) MapUtils
//					.getObject(diagTop10DeptInfoMap, "diagTop10DeptRecord");
//			if (CollectionUtils.isNotEmpty(diagTop10DeptRecordMaps)) {
//				String diagTop10DeptRecordJson = JsonUtil.objectToJson(diagTop10DeptRecordMaps);
//				List<DiagTop10DeptRecord> diagTop10DeptRecordList = JsonUtil.jsonToList(diagTop10DeptRecordJson,
//						DiagTop10DeptRecord.class);
//				List<Top10DTO> top10DTOList = getDiagTop10PTO(diagTop10DeptRecordList);
//				if (CollectionUtils.isNotEmpty(top10DTOList)) {
//					/*
//					 * Map<String, Object> diagTop10Map = new LinkedHashMap<>();
//					 * Collections.sort(top10DTOList, new Comparator<Top10DTO>() {
//					 * 
//					 * @Override public int compare(Top10DTO o1, Top10DTO o2) {
//					 * 
//					 * return o2.getNum() - o1.getNum(); } }); int index = 0; for (Top10DTO top10dto
//					 * : top10DTOList) { diagTop10Map.put("list" + index, top10dto.getList());
//					 * index++;
//					 * 
//					 * }
//					 * 
//					 * map.put("diagTop10Map", diagTop10Map);
//					 */}
//
//			}
//		}
//
//		Map<String, Object> opsTop20InfoMap = MapUtils.getMap(jsonMap, "opsTop20Info");
//		if (MapUtils.isNotEmpty(opsTop20InfoMap)) {
//			Map<String, Object> map9 = new HashMap<>();
//			String operationTop20Text = MapUtils.getString(opsTop20InfoMap, "operationTop20Text");
//			map9.put("operationTop20Text",
//					StringUtils.isEmpty(operationTop20Text) ? null : operationTop20Text.replaceAll("\n", "<w:br/>"));
//			String note = MapUtils.getString(diagTop20OrderInfoMap, "note");
//			map9.put("note", StringUtils.isEmpty(note) ? null : note.replaceAll("\n", "<w:br/>"));
//			map9.put("topOrderRecords", MapUtils.getObject(opsTop20InfoMap, "topOrderRecords"));
//			map.put("opsTop20Info", map9);
//		}
//
//		Map<String, Object> opsTop10InfoMap = MapUtils.getMap(jsonMap, "opsTop10Info");
//
//		if (MapUtils.isNotEmpty(opsTop10InfoMap)) {
//			/*
//			 * List<Map<String, Object>> opsTop10Maps = (List<Map<String, Object>>)
//			 * MapUtils.getObject(opsTop10InfoMap, "diagTop10DeptRecord"); if
//			 * (CollectionUtils.isNotEmpty(opsTop10Maps)) { String opsTop10RecordJson =
//			 * JsonUtil.objectToJson(opsTop10Maps); List<DiagTop10DeptRecord>
//			 * diagTop10DeptRecordList = JsonUtil.jsonToList(opsTop10RecordJson,
//			 * DiagTop10DeptRecord.class); List<Top10DTO> top10DTOList =
//			 * getDiagTop10PTO(diagTop10DeptRecordList); if
//			 * (CollectionUtils.isNotEmpty(top10DTOList)) { Map<String, Object> opsTop10Map
//			 * = new LinkedHashMap<>(); Collections.sort(top10DTOList, new
//			 * Comparator<Top10DTO>() {
//			 * 
//			 * @Override public int compare(Top10DTO o1, Top10DTO o2) {
//			 * 
//			 * return o2.getNum() - o1.getNum(); } }); int index = 0; for (Top10DTO top10dto
//			 * : top10DTOList) { opsTop10Map.put("list" + index, top10dto.getList());
//			 * index++;
//			 * 
//			 * }
//			 * 
//			 * map.put("opsTop10Map", opsTop10Map); }
//			 * 
//			 * }
//			 */}
//
//		Map<String, Object> deathReasonInfoMap = MapUtils.getMap(jsonMap, "deathReasonInfo");
//
//		if (MapUtils.isNotEmpty(deathReasonInfoMap)) {
//			Map<String, Object> map10 = new HashMap<>();
//			String top20OrderText = MapUtils.getString(deathReasonInfoMap, "top20OrderText");
//			map10.put("top20OrderText",
//					StringUtils.isEmpty(top20OrderText) ? null : top20OrderText.replaceAll("\n", "<w:br/>"));
//			String top20OrderNote = MapUtils.getString(deathReasonInfoMap, "top20OrderNote");
//			map10.put("top20OrderNote",
//					StringUtils.isEmpty(top20OrderNote) ? null : top20OrderNote.replaceAll("\n", "<w:br/>"));
//			map10.put("top20diagOrderRecords", MapUtils.getObject(deathReasonInfoMap, "top20diagOrderRecords"));
//			map.put("deathReasonInfo", map10);
//		}

		try {
			WordUtil.exportTemplateWord(request, response, map, "all.ftl", "统计指标综合分析报告");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * 重点疾病和手术
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@GetMapping("/majorDiseaseOperation")
	public String majorDiseaseOperation(Model model, HttpServletRequest request) {
		
		User user = (User) request.getSession().getAttribute("user");
		
		String params = request.getParameter("month");
		model.addAttribute("month", params);
		try {

			medicalService.getmajorDiseaseOperation(params, user.getOrgCode());

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/majorDiseaseOperation";
	}

	// ---------------------------------------门诊满意度详情
	// start-----------------------------------------------

	@RequestMapping("/satisfactionDetail")
	public String satisfactionDetail(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("satisfaction_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> outpatientSatisfactionMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				outpatientSatisfactionMap = MapUtils.getMap(jsonMap, "outpatientSatisfactionInfo");
				if (MapUtils.isNotEmpty(outpatientSatisfactionMap)) {
					model.addAttribute("outpatientSatisfactionInfo", outpatientSatisfactionMap);
				}
			}

			if (MapUtils.isEmpty(outpatientSatisfactionMap)) {
				OutpatientSatisfactionInfo outpatientSatisfactionInfo = medicalService
						.getOutpatientSatisfaction(statisticalReportParam, user.getOrgCode());

				model.addAttribute("outpatientSatisfactionInfo", outpatientSatisfactionInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/satisfactionDetail.page";
	}

	/**
	 * 门诊患者满意度
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@GetMapping("/outpatientSatisfaction")
	public String outpatientSatisfaction(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {

			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> outpatientSatisfactionMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				outpatientSatisfactionMap = MapUtils.getMap(jsonMap, "outpatientSatisfactionInfo");
				if (MapUtils.isNotEmpty(outpatientSatisfactionMap)) {
					model.addAttribute("outpatientSatisfactionInfo", outpatientSatisfactionMap);
				}
			}

			if (MapUtils.isEmpty(outpatientSatisfactionMap)) {
				OutpatientSatisfactionInfo outpatientSatisfactionInfo = medicalService
						.getOutpatientSatisfaction(statisticalReportParam, user.getOrgCode());

				model.addAttribute("outpatientSatisfactionInfo", outpatientSatisfactionInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/outpatientSatisfaction";
	}

	@ResponseBody
	@RequestMapping("/saveOutpatientSatisfaction")
	public Result saveOutpatientSatisfaction(HttpServletRequest request) {
		Result result = null;
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			OutpatientSatisfactionInfo outpatientSatisfactionInfo = medicalService
					.getOutpatientSatisfaction(statisticalReportParam, user.getOrgCode());

			outpatientSatisfactionInfo.setStatistionNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("outpatientSatisfactionInfo", outpatientSatisfactionInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "门诊患者满意度调查详情保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "门诊患者满意度调查详情保存失败!");
		}
		return result;
	}

	// ---------------------------------------门诊满意度详情
	// end-----------------------------------------------

	// ---------------------------------------门诊满意度对比
	// start-----------------------------------------------

	@RequestMapping("/satisfactionAnalyse")
	public String satisfactionAnalyse(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("satisfaction_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> outSatisContrastAnalysisMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				outSatisContrastAnalysisMap = MapUtils.getMap(jsonMap, "outSatisContrastAnalysisInfo");
				if (MapUtils.isNotEmpty(outSatisContrastAnalysisMap)) {
					model.addAttribute("outSatisContrastAnalysisInfo", outSatisContrastAnalysisMap);
				}
			}

			if (MapUtils.isEmpty(outSatisContrastAnalysisMap)) {
				OutSatisContrastAnalysisInfo outSatisContrastAnalysisInfo = medicalService
						.getOutSatisContrastAnalysisInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("outSatisContrastAnalysisInfo", outSatisContrastAnalysisInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/satisfactionAnalyse.page";
	}

	/**
	 * 门诊患者满意度对比
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@GetMapping("/outSatisContrastAnalysisInfo")
	public String outSatisContrastAnalysisInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> outSatisContrastAnalysisMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				outSatisContrastAnalysisMap = MapUtils.getMap(jsonMap, "outSatisContrastAnalysisInfo");
				if (MapUtils.isNotEmpty(outSatisContrastAnalysisMap)) {
					model.addAttribute("outSatisContrastAnalysisInfo", outSatisContrastAnalysisMap);
				}
			}

			if (MapUtils.isEmpty(outSatisContrastAnalysisMap)) {
				OutSatisContrastAnalysisInfo outSatisContrastAnalysisInfo = medicalService
						.getOutSatisContrastAnalysisInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("outSatisContrastAnalysisInfo", outSatisContrastAnalysisInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/outSatisContrastAnalysisInfo";
	}

	@ResponseBody
	@RequestMapping("/saveOutSatisContrastAnalysisInfo")
	public Result saveOutSatisContrastAnalysisInfo(HttpServletRequest request) {
		Result result = null;
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			OutSatisContrastAnalysisInfo outSatisContrastAnalysisInfo = medicalService
					.getOutSatisContrastAnalysisInfo(statisticalReportParam, user.getOrgCode());

			outSatisContrastAnalysisInfo.setAnalysisNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("outSatisContrastAnalysisInfo", outSatisContrastAnalysisInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "门诊患者满意度调查对比分析保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "门诊患者满意度调查对比分析保存失败!");
		}
		return result;
	}

	// ---------------------------------------门诊满意度对比
	// end-----------------------------------------------

	// --------------------------------------医疗服务与质量安全相关指标 重返类指标start
	// -------------------------------------------------
	@RequestMapping("/qcBackPage")
	public String qcBackPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("qc_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> qcBackMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				qcBackMap = MapUtils.getMap(jsonMap, "qcBackInfo");
				if (MapUtils.isNotEmpty(qcBackMap)) {
					model.addAttribute("qcBackInfo", qcBackMap);
				}
			}

			if (MapUtils.isEmpty(qcBackMap)) {
				QcBackInfo qcBackInfo = medicalService.getQcBackInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("qcBackInfo", qcBackInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/qcBackPage.page";
	}

	@GetMapping("/qcBackInfo")
	public String qcBackInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> qcBackMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				qcBackMap = MapUtils.getMap(jsonMap, "qcBackInfo");
				if (MapUtils.isNotEmpty(qcBackMap)) {
					model.addAttribute("qcBackInfo", qcBackMap);
				}
			}

			if (MapUtils.isEmpty(qcBackMap)) {
				QcBackInfo qcBackInfo = medicalService.getQcBackInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("qcBackInfo", qcBackInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/qcBackInfo";
	}

	@ResponseBody
	@RequestMapping("/saveQcBackInfo")
	public Result saveQcBackInfo(HttpServletRequest request) {
		Result result = null;
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			QcBackInfo qcBackInfo = medicalService.getQcBackInfo(statisticalReportParam, user.getOrgCode());

			qcBackInfo.setNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("qcBackInfo", qcBackInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "重返类指标保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "重返类指标保存失败!");
		}
		return result;
	}

	// --------------------------------------医疗服务与质量安全相关指标 重返类指标end
	// -------------------------------------------------

	// --------------------------------------医疗服务与质量安全相关指标 获得性指标start
	// -------------------------------------------------

	@GetMapping("/qcAcquiredPage")
	public String qcAcquiredPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("qc_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> qcAcquiredkMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				qcAcquiredkMap = MapUtils.getMap(jsonMap, "qcAcquiredInfo");
				if (MapUtils.isNotEmpty(qcAcquiredkMap)) {
					model.addAttribute("qcAcquiredInfo", qcAcquiredkMap);
				}
			}

			if (MapUtils.isEmpty(qcAcquiredkMap)) {
				QcAcquiredInfo qcAcquiredInfo = medicalService.getQcAcquiredInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("qcAcquiredInfo", qcAcquiredInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/qcAcquiredPage.page";
	}

	@GetMapping("/qcAcquiredInfo")
	public String qcAcquiredInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> qcAcquiredkMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				qcAcquiredkMap = MapUtils.getMap(jsonMap, "qcAcquiredInfo");
				if (MapUtils.isNotEmpty(qcAcquiredkMap)) {
					model.addAttribute("qcAcquiredInfo", qcAcquiredkMap);
				}
			}

			if (MapUtils.isEmpty(qcAcquiredkMap)) {
				QcAcquiredInfo qcAcquiredInfo = medicalService.getQcAcquiredInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("qcAcquiredInfo", qcAcquiredInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/qcAcquiredInfo";
	}

	@ResponseBody
	@RequestMapping("/saveQcAcquiredInfo")
	public Result saveQcAcquiredInfo(HttpServletRequest request) {
		Result result = null;
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			QcAcquiredInfo qcAcquiredInfo = medicalService.getQcAcquiredInfo(statisticalReportParam, user.getOrgCode());
			qcAcquiredInfo.setNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("qcAcquiredInfo", qcAcquiredInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "获得性指标保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "获得性指标保存失败!");
		}
		return result;
	}

	// --------------------------------------医疗服务与质量安全相关指标 获得性指标end
	// -------------------------------------------------

	// --------------------------------------医疗服务与质量安全相关指标 20个重点病种相关指标start
	// -------------------------------------------------
	@GetMapping("/major20DiagPage")
	public String major20DiagPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("qc_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);

			try {
				StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
						.getAttribute("statisticalReportParam");
				model.addAttribute("statisticalReportParam", statisticalReportParam);

				Map<String, Object> major20DiagMap = null;
				Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				if (MapUtils.isNotEmpty(jsonMap)) {
					major20DiagMap = MapUtils.getMap(jsonMap, "major20DiagInfo");
					if (MapUtils.isNotEmpty(major20DiagMap)) {
						model.addAttribute("major20DiagInfo", major20DiagMap);
					}
				}

				if (MapUtils.isEmpty(major20DiagMap)) {
					Major20DiagInfo major20DiagInfo = medicalService.getMajor20DiagInfo(statisticalReportParam, user.getOrgCode());
					model.addAttribute("major20DiagInfo", major20DiagInfo);
				}

			} catch (Exception e) {
				e.printStackTrace();
			}
		return "query/major20DiagPage.page";
	}
	
	
	
	
	@GetMapping("/major20DiagInfo")
	public String major20DiagInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> major20DiagMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				major20DiagMap = MapUtils.getMap(jsonMap, "major20DiagInfo");
				if (MapUtils.isNotEmpty(major20DiagMap)) {
					model.addAttribute("major20DiagInfo", major20DiagMap);
				}
			}

			if (MapUtils.isEmpty(major20DiagMap)) {
				Major20DiagInfo major20DiagInfo = medicalService.getMajor20DiagInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("major20DiagInfo", major20DiagInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/major20DiagInfo";
	}

	@ResponseBody
	@RequestMapping("/saveMajor20DiagInfo")
	public Result saveMajor20DiagInfo(HttpServletRequest request) {
		Result result = null;
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			Major20DiagInfo major20DiagInfo = medicalService.getMajor20DiagInfo(statisticalReportParam, user.getOrgCode());
			major20DiagInfo.setNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("major20DiagInfo", major20DiagInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "重点病种相关指标保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "重点病种相关指标保存失败!");
		}
		return result;
	}

	// --------------------------------------医疗服务与质量安全相关指标 20个重点病种相关指标end
	// -------------------------------------------------

	// --------------------------------------医疗服务与质量安全相关指标 20个重点手术相关指标start
	// -------------------------------------------------
	
	
	
	@GetMapping("/major20OpPage")
	public String major20OpPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("qc_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> major20OperationDiagMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				major20OperationDiagMap = MapUtils.getMap(jsonMap, "major20OperationInfo");
				if (MapUtils.isNotEmpty(major20OperationDiagMap)) {
					model.addAttribute("major20OperationInfo", major20OperationDiagMap);
				}
			}

			if (MapUtils.isEmpty(major20OperationDiagMap)) {
				Major20DiagInfo major20DiagInfo = medicalService.getMajor20OperationInfo(statisticalReportParam,
						user.getOrgCode());
				model.addAttribute("major20OperationInfo", major20DiagInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/major20OpPage.page";
	}
	
	
	@GetMapping("/major20OperationInfo")
	public String major20OperationInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> major20OperationDiagMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				major20OperationDiagMap = MapUtils.getMap(jsonMap, "major20OperationInfo");
				if (MapUtils.isNotEmpty(major20OperationDiagMap)) {
					model.addAttribute("major20OperationInfo", major20OperationDiagMap);
				}
			}

			if (MapUtils.isEmpty(major20OperationDiagMap)) {
				Major20DiagInfo major20DiagInfo = medicalService.getMajor20OperationInfo(statisticalReportParam,
						user.getOrgCode());
				model.addAttribute("major20OperationInfo", major20DiagInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/major20OperationInfo";
	}

	@ResponseBody
	@RequestMapping("/saveMajor20OperationInfo")
	public Result saveMajor20OperationInfo(HttpServletRequest request) {
		Result result = null;
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			Major20DiagInfo major20OperationInfo = medicalService.getMajor20OperationInfo(statisticalReportParam,
					user.getOrgCode());
			major20OperationInfo.setNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("major20OperationInfo", major20OperationInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "重点病种相关指标保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "重点病种相关指标保存失败!");
		}
		return result;
	}

	// --------------------------------------医疗服务与质量安全相关指标 20个重点手术相关指标end
	// -------------------------------------------------

	// --------------------------------------医疗服务与质量安全相关指标 16个重点肿瘤非手术治疗相关指标start
	// -------------------------------------------------
	
	
	@GetMapping("/majorTumourNonOpPage")
	public String majorTumourNonOpPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("qc_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> majorTumourNonOpInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				majorTumourNonOpInfoMap = MapUtils.getMap(jsonMap, "majorTumourNonOpInfo");
				if (MapUtils.isNotEmpty(majorTumourNonOpInfoMap)) {
					model.addAttribute("majorTumourNonOpInfo", majorTumourNonOpInfoMap);
				}
			}

			if (MapUtils.isEmpty(majorTumourNonOpInfoMap)) {
				Major20DiagInfo major20DiagInfo = medicalService.getMajorTumourNonOpInfo(statisticalReportParam,
						user.getOrgCode());
				model.addAttribute("majorTumourNonOpInfo", major20DiagInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/majorTumourNonOpPage.page";
	}
	
	
	
	@GetMapping("/majorTumourNonOpInfo")
	public String majorTumourNonOpInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> majorTumourNonOpInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				majorTumourNonOpInfoMap = MapUtils.getMap(jsonMap, "majorTumourNonOpInfo");
				if (MapUtils.isNotEmpty(majorTumourNonOpInfoMap)) {
					model.addAttribute("majorTumourNonOpInfo", majorTumourNonOpInfoMap);
				}
			}

			if (MapUtils.isEmpty(majorTumourNonOpInfoMap)) {
				Major20DiagInfo major20DiagInfo = medicalService.getMajorTumourNonOpInfo(statisticalReportParam,
						user.getOrgCode());
				model.addAttribute("majorTumourNonOpInfo", major20DiagInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/majorTumourNonOpInfo";
	}

	@ResponseBody
	@RequestMapping("/saveMajorTumourNonOpInfo")
	public Result saveMajorTumourNonOpInfo(HttpServletRequest request) {
		Result result = null;
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			Major20DiagInfo majorTumourNonOpInfo = medicalService.getMajorTumourNonOpInfo(statisticalReportParam,
					user.getOrgCode());
			majorTumourNonOpInfo.setNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("majorTumourNonOpInfo", majorTumourNonOpInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "重点肿瘤非手术治疗相关指标保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "重点肿瘤非手术治疗相关指标保存失败!");
		}
		return result;
	}

	// --------------------------------------医疗服务与质量安全相关指标 16个重点肿瘤非手术治疗相关指标end
	// -------------------------------------------------

	// --------------------------------------医疗服务与质量安全相关指标14个重点肿瘤手术治疗相关指标start
	// -------------------------------------------------
	
	@GetMapping("/majorTumourOpPage")
	public String majorTumourOpPage(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("qc_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> majorTumourOpInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				majorTumourOpInfoMap = MapUtils.getMap(jsonMap, "majorTumourOpInfo");
				if (MapUtils.isNotEmpty(majorTumourOpInfoMap)) {
					model.addAttribute("majorTumourOpInfo", majorTumourOpInfoMap);
				}
			}

			if (MapUtils.isEmpty(majorTumourOpInfoMap)) {
				Major20DiagInfo major20DiagInfo = medicalService.getMajorTumourOpInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("majorTumourOpInfo", major20DiagInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/majorTumourOpPage.page";
	}
	
	
	
	@GetMapping("/majorTumourOpInfo")
	public String majorTumourOpInfo(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> majorTumourOpInfoMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				majorTumourOpInfoMap = MapUtils.getMap(jsonMap, "majorTumourOpInfo");
				if (MapUtils.isNotEmpty(majorTumourOpInfoMap)) {
					model.addAttribute("majorTumourOpInfo", majorTumourOpInfoMap);
				}
			}

			if (MapUtils.isEmpty(majorTumourOpInfoMap)) {
				Major20DiagInfo major20DiagInfo = medicalService.getMajorTumourOpInfo(statisticalReportParam, user.getOrgCode());
				model.addAttribute("majorTumourOpInfo", major20DiagInfo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "medical_record/home_page/majorTumourOpInfo";
	}

	@ResponseBody
	@RequestMapping("/saveMajorTumourOpInfo")
	public Result saveMajorTumourOpInfo(HttpServletRequest request) {
		Result result = null;
		String note = request.getParameter("note");
		User user = (User) request.getSession().getAttribute("user");
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			Major20DiagInfo majorTumourNonOpInfo = medicalService.getMajorTumourOpInfo(statisticalReportParam, user.getOrgCode());
			majorTumourNonOpInfo.setNote(note);

			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			jsonMap.put("majorTumourOpInfo", majorTumourNonOpInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "重点肿瘤手术治疗相关指标保存成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "重点肿瘤手术治疗相关指标保存失败!");
		}
		return result;
	}

	// --------------------------------------医疗服务与质量安全相关指标 14个重点肿瘤手术治疗相关指标end
	// -------------------------------------------------

	@ResponseBody
	@RequestMapping(value = "/getStatisticalReportParamPageInfo")
	public void getStatisticalReportParamPageInfo(HttpServletRequest request, HttpServletResponse response,
			PageParam pageParam) {
		PageData<StatisticalReportParam> pd = new PageData<StatisticalReportParam>();

		PageInfo<StatisticalReportParam> pageInfo = medicalService.getStatisticalReportParamPageInfo(pageParam);

		List<StatisticalReportParam> list = pageInfo.getList();

		if (list != null && list.size() > 0) {
			pd.setCount((int) pageInfo.getTotal());
			pd.setData(list);
		} else {
			pd.setCount(0);
			pd.setData(new ArrayList<StatisticalReportParam>());
		}

		String json = JsonUtil.objectToJson(pd);

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out;
		try {
			out = response.getWriter();
			out.print(json);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	
	//--------------------------------------------------
	@GetMapping("/performanceGeneral")
	public String performanceGeneral(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("performance_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> generalPerformaceMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				generalPerformaceMap = MapUtils.getMap(jsonMap, "generalPerformaceInfo");
				if (MapUtils.isNotEmpty(generalPerformaceMap)) {
					model.addAttribute("generalPerformaceInfo", generalPerformaceMap);
				}
			}

			if (MapUtils.isEmpty(generalPerformaceMap)) {
				GeneralPerformace generalPerformace = medicalService.getPerformanceGeneral(statisticalReportParam,user.getOrgCode());
				model.addAttribute("generalPerformaceInfo", generalPerformace);
				jsonMap.put("generalPerformaceInfo", generalPerformace);
				FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/performanceGeneralPage.page";
	}
	
	
	
	
	@ResponseBody
	@PostMapping("/saveGeneralPerformance")
	public Result saveGeneralPerformance(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {

			
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			
			GeneralPerformace generalPerformace = medicalService.getPerformanceGeneral(statisticalReportParam,user.getOrgCode());
			jsonMap.put("generalPerformaceInfo", generalPerformace);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");


			result = new Result(true, "总体情况保存成功!");
		} catch (Exception e) {
			result = new Result(false, "总体情况保存失败,失败原因:"+e.getMessage());
			e.printStackTrace();
		}

		return result;
	}
	
	
	@ResponseBody
	@RequestMapping(value = "exportGeneralPerformanceWord")
	public void exportGeneralPerformanceWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		
		GeneralPerformace generalPerformace = medicalService.getPerformanceGeneral(statisticalReportParam,user.getOrgCode());

		

		map.put("generalPerformaceInfo",generalPerformace);

		map.put("statisticalReportParam", statisticalReportParam);

		WordUtil.exportTemplateWord(request, response, map, "generalPerformace.ftl", "绩效考核总体指标");

	}
	
	
	
	
	@GetMapping("/ssrsPerformance")
	public String ssrsPerformance(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("performance_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> ssrsPerformanceMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				ssrsPerformanceMap = MapUtils.getMap(jsonMap, "ssrsPerformanceInfo");
				if (MapUtils.isNotEmpty(ssrsPerformanceMap)) {
					model.addAttribute("ssrsPerformanceInfo", ssrsPerformanceMap);
				}
			}

			if (MapUtils.isEmpty(ssrsPerformanceMap)) {
				PerformanceInfo ssrsPerformanceInfo = medicalService.getSsrsPerformance(statisticalReportParam,user.getOrgCode());
				model.addAttribute("ssrsPerformanceInfo", ssrsPerformanceInfo);
				
				jsonMap.put("ssrsPerformanceInfo", ssrsPerformanceInfo);
				
				FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
	
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/ssrsPerformancePage.page";
	}
	
	
	
	@ResponseBody
	@RequestMapping(value = "exportSsrsPerformanceWord")
	public void exportSsrsPerformanceWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		
		PerformanceInfo ssrsPerformanceInfo = medicalService.getSsrsPerformance(statisticalReportParam,user.getOrgCode());

		
		
		map.put("statisticalReportParam", statisticalReportParam);

		map.put("note",StringUtils.isEmpty(ssrsPerformanceInfo.getNote()) ? null : ssrsPerformanceInfo.getNote().replaceAll("\n", "<w:br/>"));

		map.put("list", ssrsPerformanceInfo.getPerformanceList());

		WordUtil.exportTemplateWord(request, response, map, "ssrsPerformance.ftl", "手术人数及手术占比分析");

	}
	
	
	
	
	@ResponseBody
	@PostMapping("/saveSsrsPerformance")
	public Result saveSsrsPerformance(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {

			
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			
			PerformanceInfo ssrsPerformanceInfo = medicalService.getSsrsPerformance(statisticalReportParam,user.getOrgCode());
			
			jsonMap.put("ssrsPerformanceInfo", ssrsPerformanceInfo);
			
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");


			result = new Result(true, "手术人数及手术占比分析保存成功!");
		} catch (Exception e) {
			result = new Result(false, "手术人数及手术占比分析失败,失败原因:"+e.getMessage());
			e.printStackTrace();
		}

		return result;
	}
	
	
	
	
	
	@GetMapping("/sjssPerformance")
	public String sjssPerformance(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("performance_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> sjssPerformanceMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				sjssPerformanceMap = MapUtils.getMap(jsonMap, "sjssPerformanceInfo");
				if (MapUtils.isNotEmpty(sjssPerformanceMap)) {
					model.addAttribute("sjssPerformanceInfo", sjssPerformanceMap);
				}
			}

			if (MapUtils.isEmpty(sjssPerformanceMap)) {
				PerformanceInfo sjssPerformanceInfo = medicalService.getSjssPerformance(statisticalReportParam,user.getOrgCode());
				model.addAttribute("sjssPerformanceInfo", sjssPerformanceInfo);
				jsonMap.put("sjssPerformanceInfo", sjssPerformanceInfo);
				
				FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/sjssPerformancePage.page";
	}
	
	
	
	
	@ResponseBody
	@RequestMapping(value = "exportSjssPerformanceWord")
	public void exportSjssPerformanceWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		
		PerformanceInfo sjssPerformanceInfo = medicalService.getSjssPerformance(statisticalReportParam,user.getOrgCode());
		
		
		map.put("statisticalReportParam", statisticalReportParam);

		map.put("note",StringUtils.isEmpty(sjssPerformanceInfo.getNote()) ? null : sjssPerformanceInfo.getNote().replaceAll("\n", "<w:br/>"));

		map.put("list", sjssPerformanceInfo.getPerformanceList());

		WordUtil.exportTemplateWord(request, response, map, "sjssPerformance.ftl", "四级手术人数及四级手术占比");

	}
	
	
	@ResponseBody
	@PostMapping("/saveSjssPerformance")
	public Result saveSjssPerformance(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {

			
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			
			PerformanceInfo sjssPerformanceInfo = medicalService.getSjssPerformance(statisticalReportParam,user.getOrgCode());
			jsonMap.put("sjssPerformanceInfo", sjssPerformanceInfo);
			
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "四级手术人数及四级手术占比保存成功!");
		} catch (Exception e) {
			result = new Result(false, "四级手术人数及四级手术占比失败,失败原因:"+e.getMessage());
			e.printStackTrace();
		}

		return result;
	}
	
	
	
	@GetMapping("/miniPerformance")
	public String miniPerformance(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("performance_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> sjssPerformanceMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				sjssPerformanceMap = MapUtils.getMap(jsonMap, "miniPerformanceInfo");
				if (MapUtils.isNotEmpty(sjssPerformanceMap)) {
					model.addAttribute("miniPerformanceInfo", sjssPerformanceMap);
				}
			}

			if (MapUtils.isEmpty(sjssPerformanceMap)) {
				PerformanceInfo miniPerformanceInfo = medicalService.getminiPerformance(statisticalReportParam,user.getOrgCode());
				model.addAttribute("miniPerformanceInfo", miniPerformanceInfo);
				
				jsonMap.put("miniPerformanceInfo", miniPerformanceInfo);
				FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/miniPerformancePage.page";
	}
	
	
	
	@ResponseBody
	@RequestMapping(value = "exportMiniPerformanceWord")
	public void exportMiniPerformanceWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		
		PerformanceInfo miniPerformanceInfo = medicalService.getminiPerformance(statisticalReportParam,user.getOrgCode());
		
		
		map.put("statisticalReportParam", statisticalReportParam);

		map.put("note",StringUtils.isEmpty(miniPerformanceInfo.getNote()) ? null : miniPerformanceInfo.getNote().replaceAll("\n", "<w:br/>"));

		map.put("list", miniPerformanceInfo.getPerformanceList());

		WordUtil.exportTemplateWord(request, response, map, "miniPerformance.ftl", "微创手术人数及微创手术占比");

	}
	
	
	
	@ResponseBody
	@PostMapping("/saveMiniPerformance")
	public Result saveMiniPerformance(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {

			
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			
			PerformanceInfo miniPerformanceInfo = medicalService.getminiPerformance(statisticalReportParam,user.getOrgCode());
			
			jsonMap.put("miniPerformanceInfo", miniPerformanceInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "微创手术人数及微创手术占比保存成功!");
		} catch (Exception e) {
			result = new Result(false, "微创手术人数及微创手术占比失败,失败原因:"+e.getMessage());
			e.printStackTrace();
		}

		return result;
	}
	
	
	
	@GetMapping("/singleDiagQc")
	public String singleDiagQc(Model model, HttpServletRequest request) {
		LeftMenuPojo leftMenu = LeftMenuPojo.GetLeftMenu("performance_module");
		User user = (User) request.getSession().getAttribute("user");
		String leftMenuJson = JsonUtils.objectToJson(leftMenu);
		model.addAttribute("leftMenuJson", leftMenuJson);
		try {
			StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
					.getAttribute("statisticalReportParam");
			model.addAttribute("statisticalReportParam", statisticalReportParam);

			Map<String, Object> singleDiagQcMap = null;
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			if (MapUtils.isNotEmpty(jsonMap)) {
				singleDiagQcMap = MapUtils.getMap(jsonMap, "singleDiagQcInfo");
				if (MapUtils.isNotEmpty(singleDiagQcMap)) {
					model.addAttribute("singleDiagQcInfo", singleDiagQcMap);
				}
			}

			if (MapUtils.isEmpty(singleDiagQcMap)) {
				SingleDiagQcInfo singleDiagQcInfo = medicalService.getSingleDiagQcInfo(statisticalReportParam,user.getOrgCode());
				model.addAttribute("singleDiagQcInfo", singleDiagQcInfo);
				jsonMap.put("singleDiagQcInfo", singleDiagQcInfo);
				
				FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
						statisticalReportParam.getOnlyId() + ".json");
				
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return "query/singleDiagQcPage.page";
	}
	
	
	
	@ResponseBody
	@RequestMapping(value = "exportSingleDiagQcWord")
	public void exportSingleDiagQcWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<>();
		User user = (User) request.getSession().getAttribute("user");
		
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");

		SingleDiagQcInfo singleDiagQcInfo = medicalService.getSingleDiagQcInfo(statisticalReportParam,user.getOrgCode());
		
		map.put("statisticalReportParam", statisticalReportParam);
		map.put("list", singleDiagQcInfo.getSingleDiagQcRecords());

		WordUtil.exportTemplateWord(request, response, map, "singleDiagQc.ftl", "单病种质量控制");

	}
	
	
	
	
	@ResponseBody
	@PostMapping("/saveSingleDiagQc")
	public Result saveSingleDiagQc(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		StatisticalReportParam statisticalReportParam = (StatisticalReportParam) request.getSession()
				.getAttribute("statisticalReportParam");
		Result result = null;
		try {

			
			Map<String, Object> jsonMap = FileUtil.readLineFile("D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");
			
			SingleDiagQcInfo singleDiagQcInfo = medicalService.getSingleDiagQcInfo(statisticalReportParam,user.getOrgCode());
			String note = request.getParameter("note");
			singleDiagQcInfo.setNote(note);
			jsonMap.put("singleDiagQcInfo", singleDiagQcInfo);
			FileUtil.createOrEditFile(JsonUtil.objectToJson(jsonMap), "D://publics/report/json/",
					statisticalReportParam.getOnlyId() + ".json");

			result = new Result(true, "单病种质量控制保存成功!");
		} catch (Exception e) {
			result = new Result(false, "单病种质量控制保存失败,失败原因:"+e.getMessage());
			e.printStackTrace();
		}

		return result;
	}
	
	
	
	
	

	
	
}
